嗨,我有一个以下查询,它检查代码以确定何时输入或查看它。
declare @timestamp datetime;
select
case @timestamp
when a.updatedDate =1760 then 'Entered on' +a.updatedDate
when a.updatedDate=1710 then 'Viewed on' +a.updatedDate
else 'Last Updated on'+ a.updatedDate
end
from t_mainTable a
where a.id=@Id;
当我尝试运行此查询时,它给了我错误
Msg 102, Level 15, State 1, Procedure p_xxxx, line 40
Incorrect syntax near '='.
when行中存在一些syntex错误。请让我知道如何更正此谢谢
编写case语句有两种方法,您似乎在结合使用这两种方法
case a.updatedDate
when 1760 then 'Entered on' + a.updatedDate
when 1710 then 'Viewed on' + a.updatedDate
else 'Last Updated on' + a.updateDate
end
或者
case
when a.updatedDate = 1760 then 'Entered on' + a.updatedDate
when a.updatedDate = 1710 then 'Viewed on' + a.updatedDate
else 'Last Updated on' + a.updateDate
end
是等效的。它们可能不起作用,因为您可能需要将日期类型转换为varchars才能将其附加到其他varchars。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句