求一存储过程

kevinhu520 2008-09-25 03:49:54

编号,日期,提交人,工作服,耳机,衣柜等字段


提交部门,
状态类型, 包括:全部,办理完毕,未办理完毕
编号,
开始日期,
结束日期,
按照最后上班时间取
按照申请时间取等查询条件

根据下面的IF语句写存储过程
bumen == 提交部门
jilu == 状态类型
bianhao == 编号
xianxiang13 == 按什么时间取 如果是"y":按照最后上班时间取
如果是"n",按照申请时间取
chuli == 做过工作时间
riqi == 开始日期
riqi3 == 结束日期


if bumen<>"全部" then
strs=strs+" and bumen='"+cstr(bumen)+"'"
end if
if jilu<>"全部" then
if jilu="办理完毕" then
strs=strs+" and (jilu='o' or jilu='w')"
else
strs=strs+" and jilu<>'o' and jilu<>'w'"
end if
end if
if bianhao<>"全部" then
strs=strs+" and bianhao='"+cstr(bianhao)+"'"
end if
if request("xianxiang13")<>"y" then
if riqi<>"2008-x-xx" then
strs=strs+" and cdate(riqi)>=#"+trim(cstr(riqi))+"#"
end if
if riqi3<>"2008-x-xx" then
strs=strs+" and cdate(riqi)<#"+trim(cstr(riqi3))+"#"
end if
else
if riqi<>"2008-x-xx" then
strs=strs+" and cdate(chuli)>=#"+trim(cstr(riqi))+"#"
end if
if riqi3<>"2008-x-xx" then
strs=strs+" and cdate(chuli)<#"+trim(cstr(riqi3))+"#"
end if
end if

请各位大虾帮帮忙
小弟在此谢过
谢谢

...全文
128 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
-晴天 2008-09-25
  • 打赏
  • 举报
回复
CREATE PROCEDURE [dbo].[getInfo]
(
@bumen nvarchar(20),
@jilu nvarchar(20),
@bianhao nvarchar(5),
@xianxiang13 varchar(2),
@datetime datetime,
@chuli datetime
)--WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ON;

declare @searchstr nvarchar(200)
set @searchstr='select * from tablename where '
if @bumen<>'全部'
set @searchstr=@searchstr+'提交部门='''+@bumen+''' and '
if @jilu<>'全部'
begin
if @jilu='办理完毕'
set @searchstr=@searchstr+'(状态类型=''o'' or 状态类型=''w'') and '
else
set @searchstr=@searchstr+'(状态类型<>''o'' and 状态类型<>''w'') and '
end
if @bianhao<>'全部'
set @searchstr=@searchstr+'编号='+@bianhao+' and '
if @xianxiang13<>'y' or @xianxiang13<>'Y'
set @searchstr=@searchstr+convert(varchar(10),@datetime,120)+'>=开始日期 and '+convert(varchar(10),@datetime,120)+'<结束日期'
else
set @searchstr=@searchstr+'最后工作时间>=开始日期 and 最后工作时间<结束日期'

if right(@searchstr,5)=' and '
set @searchstr=left(@searchstr,len(@searchstr)-5)
if right(@searchstr,7)=' where '
set @searchstr=left(@searchstr,len(@searchstr)-7)

exec (@searchstr)

END
kevinhu520 2008-09-25
  • 打赏
  • 举报
回复
up
pt1314917 2008-09-25
  • 打赏
  • 举报
回复
力气活。。。
kevinhu520 2008-09-25
  • 打赏
  • 举报
回复
ID INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
编号 INT NULL, --bianhao
提交日期 DATETIME NULL, --riqi
提交部门 VARCHAR(50) NULL, --bumen
提交人 VARCHAR(16) NULL, --baozhangren
提交时间 DATETIME NULL, --baozhangshijian
申请时间 DATETIME NULL, --xianxiang11
值班长谈话 VARCHAR(5000) NULL, --tanhua
--申请人姓名 VARCHAR(16) NULL, --xianxiang
--工号 VARCHAR(8) NULL, --xianxiang1
--团队 VARCHAR(10) NULL, --xianxiang3
--批次 VARCHAR(10) NULL, --xianxiang2
--岗位 VARCHAR(10) NULL, --xianxiang4
--电话 VARCHAR(15) NULL, --xianxiang5
--虚拟网 VARCHAR(20) NULL, --xianxiang7
--通信地址 VARCHAR(50) NULL, --xianxiang6
--派遣公司 VARCHAR(50) NULL, --xianxiang8
--用工性质 VARCHAR(20) NULL, --xianxiang9
--提前申请 VARCHAR(2) NULL, --xianxiang13
--离职后职业 VARCHAR(50) NULL, --xianxiang10
--预定离职时间 DATETIME NULL, --xianxiang12
离职事由 VARCHAR(500) NULL, --shiyou
区域主管 VARCHAR(20) NULL, --weixiuren
编酬序号 VARCHAR(20) NULL, --weixiushijian
最后工作时间 DATETIME NULL, --chuli
是否正常 VARCHAR(6) NULL, --renwei
是否辞退 VARCHAR(6) NULL, --xiufushijian
是否通知 VARCHAR(6) NULL, --manyidu
审批意见 VARCHAR(500) NULL, --yanshoushijian
审批时间 DATETIME NULL, --shoulishijian
--人力资源意见 VARCHAR(500) NULL, --wenjianming1
工号牌 VARCHAR(10) NULL, --baozhangren1
耳机编号 VARCHAR(50) NULL, --zuoxihao
衣柜号 VARCHAR(50) NULL, --zuoxihao1
工作服 VARCHAR(50) NULL, --diaodu1
oa名 VARCHAR(50) NULL, --oa
综合管理员意见 VARCHAR(500) NULL, --beizhu1
交接时间 DATETIME NULL, --yanshouren
综合支持员 VARCHAR(50) NULL, --zerenren
劳务派遣公司 VARCHAR(500) NULL, --wenjianming
赔偿1 VARCHAR(50) NULL, --jianyi1
赔偿2 VARCHAR(50) NULL, --jianyi2
赔偿3 VARCHAR(50) NULL, --jianyi3
赔偿4 VARCHAR(50) NULL, --jianyi4
赔偿5 VARCHAR(50) NULL, --jianyi5
状态类型 VARCHAR(10) NULL --jilu
中国风 2008-09-25
  • 打赏
  • 举报
回复
把以上變量的類型貼出來
子陌红尘 2008-09-25
  • 打赏
  • 举报
回复
数据库是ACCESS?
中国风 2008-09-25
  • 打赏
  • 举报
回复
?
這是程序調用格式哦

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧