SQL where条件case when then

jaccheng 2014-10-30 09:37:35
where( case when @time1<>@time2 then
(convert(char(10),so.PayDate,120) between @time1 and @time2)
case when @time1=@time2 then (convert(char(10),so.PayDate,120)=@time1))
求大神改改。如果@time1=@time2 条件就是 where convert(char(10),so.PayDate,120)=@time1
如果@time1<>@time2 条件就是 where convert(char(10),so.PayDate,120) between @time1 and @time2
...全文
3781 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
还在加载中灬 2014-10-30
  • 打赏
  • 举报
回复
如上 另外,纠正下你的语法,CASE 要有END ,然后两个或级的判断,用OR隔开 最后,这种作日期范围条件限制,不建议在日期列上做变化, 可以改为where so.PayDate>= @time1 and so.PayDate<@time2,这样形式速度最快~
卖水果的net 2014-10-30
  • 打赏
  • 举报
回复

--你就用这一句就够了

where convert(char(10),so.PayDate,120) between @time1 and @time2

--当 @time1 = @time2 时,他与

 where convert(char(10),so.PayDate,120)=@time1

--等价

22,301

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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