标题:有关语句有错..
只看楼主
qq402716710
Rank: 1
等 级:新手上路
帖 子:91
专家分:0
注 册:2013-1-14
结帖率:92.86%
 问题点数:0 回复次数:4 
有关语句有错..
select  ch,gname,cx,lxr,lxrtel,logdate,cyear
from tbxlclzl
where datediff(month,logdate,getdate()+5)%6=0
and
case when month(dateadd(month,datediff(month,logdate,getdate()+5),logdate)+5)>
month(dateadd(month,datediff(month,logdate,getdate()+5),logdate))
then
datediff(day,getdate()+5,dateadd(month,datediff(month,logdate,getdate()+5),logdate))
between -5
and 0
else
datediff(day,getdate(),dateadd(month,datediff(month,logdate,getdate()+5),logdate))
between 0
and 5
end
and color='货车'
and awycens = 1

提示between附近有错,但是我把between上面的datediff(day,getdate()+5,dateadd(month,datediff(month,logdate,getdate()+5),logdate))
放到select随便找条件查询都能得出一个数值,为什么between的时候就不行呢..求解

搜索更多相关主题的帖子: 货车 between color where 
2013-01-24 14:02
qq402716710
Rank: 1
等 级:新手上路
帖 子:91
专家分:0
注 册:2013-1-14
得分:0 
select  ch,gname,cx,lxr,lxrtel,logdate,cyear
from tbxlclzl
where datediff(month,logdate,getdate()+5)%6=0
and
month(dateadd(month,datediff(month,logdate,getdate()+5),logdate)+5)>
month(dateadd(month,datediff(month,logdate,getdate()+5),logdate))
and color='货车'
and awycens = 1
and
datediff(day,getdate()+5,dateadd(month,datediff(month,logdate,getdate()+5),logdate))
between -5
and 0
union all
select  ch,gname,cx,lxr,lxrtel,logdate,cyear
from tbxlclzl
where datediff(month,logdate,getdate()+5)%6=0
and
month(dateadd(month,datediff(month,logdate,getdate()+5),logdate)+5)=
month(dateadd(month,datediff(month,logdate,getdate()+5),logdate))
and
datediff(day,getdate(),dateadd(month,datediff(month,logdate,getdate()+5),logdate))
between 0
and 5
and color='货车'
and awycens = 1
改成这样就可以了..我晕
2013-01-24 15:11
qq402716710
Rank: 1
等 级:新手上路
帖 子:91
专家分:0
注 册:2013-1-14
得分:0 
知道是为什么吗?为什么条件中不能使用CASE when 语句
2013-01-24 15:55
xiaolee
Rank: 2
等 级:论坛游民
帖 子:35
专家分:12
注 册:2013-3-11
得分:0 
表示看不懂
2013-03-15 11:40
Aviva_Wang
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:苏州
等 级:贵宾
威 望:26
帖 子:701
专家分:2382
注 册:2013-3-12
得分:0 
你的case是放where中了,当然不可以了呀

asp
2013-03-15 13:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-397490-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.728916 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved