一个sql语句,求高手过来看看如何写

t_sheng 2011-11-28 02:18:20
想写个存储过程,传两个参数 :一个 时间,还有一个是周期数
有个表里有两个时间,cr.tabDate 有可能是空的,下面的where中case怎么写
关键是
(case ISNULL(cr.tabDate,0)
when 0 then select datediff(DAY,cr.billdate,@nowData) = @day
else (select datediff(DAY,cr.tabDate,@nowData)) = @day
end)

要怎么加

create procedure ud_getRemindRepair
@nowData datetime,
@day varchar
as

select gr.billid,cr.code,cr.billdate,cr.Mobile from goodsrecord gr
left join clientrepair cr on cr.repairid=gr.billid
where ISNULL(gr.goodshabitus,0)=0 and ISNULL(gr.vrhabitus,0)=0 and notetype=50 and
(case ISNULL(cr.tabDate,0)
when 0 then select datediff(DAY,cr.billdate,@nowData) = @day
else (select datediff(DAY,cr.tabDate,@nowData)) = @day
end)
group by gr.billid,cr.code,cr.billdate,cr.Mobile
...全文
138 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
t_sheng 2011-11-28
  • 打赏
  • 举报
回复
谢谢各位 ,出来了
风车呼噜噜 2011-11-28
  • 打赏
  • 举报
回复

select gr.billid,cr.code,cr.billdate,cr.Mobile from goodsrecord gr
left join clientrepair cr on cr.repairid=gr.billid
where ISNULL(gr.goodshabitus,0)=0 and ISNULL(gr.vrhabitus,0)=0 and notetype=50 and
(case ISNULL(cr.tabDate,0)
when 0 then datediff(DAY,cr.billdate,@nowData)
else datediff(DAY,cr.tabDate,@nowData)
end) = @day
group by gr.billid,cr.code,cr.billdate,cr.Mobile


试试
快溜 2011-11-28
  • 打赏
  • 举报
回复
create procedure ud_getRemindRepair
@nowData datetime=null,
@day int=0
as

select gr.billid,cr.code,cr.billdate,cr.Mobile from goodsrecord gr
left join clientrepair cr on cr.repairid=gr.billid
where
datediff(DAY,cr.billdate,isnull(@nowData,cr.billdate)) = @day
group by gr.billid,cr.code,cr.billdate,cr.Mobile
t_sheng 2011-11-28
  • 打赏
  • 举报
回复
这个 @day 应该是int

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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