我数据库表contents里有color (varchar)和publishdate(datetime)两个字段
现在需要查询并显示两个星期之内的color字段设为红色(color='red')根据publishdate字段与当前日期比较(publishdate>getdate()-14)
而两个星期之前的color原本输出显示,不改变表里的数据,只根据条件改变显示的数据
我的语句是这样的
select (case when publishdate>getdate()-111 then color when publishdate<getdate()-111 then color end) as color,
publishdate from contents
如果case when then 里边用color='red' 会提示等号错误
大哥们帮帮忙,谢谢了
(case
when datediff(dd,publishdate,getdate())<=14 then 'red'
else color
end) as color,
publishdate
from
contents
publishdate from contents
(case when datediff(day,publishdate,getdate())<14 then 'red' else color end )as color,
publishdate
from
contents