我想在WASE CASE中使用多个条件。
我遇到以下错误
消息4104,第16层,状态1,第18行
无法绑定多部分标识符“ TableName.AAADPAddNoOfDates”
SELECT CASE
WHEN ((LTRIM(RTRIM(TableName.AAADPPapCode)) = (LTRIM(RTRIM(@PapCode))))
AND (DATEDIFF(DAY, (CONVERT(date, @PubDate, 111)), (CONVERT(date, CURRENT_TIMESTAMP, 111)))) > (TableName.AAADPAddNoOfDates)
AND (LTRIM(RTRIM(TableName.AAADPSysOperator))) != (LTRIM(RTRIM(@UserName)))) THEN 1
ELSE 0
END AS ErrorTag;
答案 0 :(得分:0)
CASE
语句看起来不错,但是您缺少指定从中选择表的FROM
子句。
答案 1 :(得分:0)
您没有指定要从中检索输出的表格。
SELECT CASE
WHEN ((LTRIM(RTRIM(TableName.AAADPPapCode)) = (LTRIM(RTRIM(@PapCode))))
AND (DATEDIFF(DAY, (CONVERT(date, @PubDate, 111)), (CONVERT(date, CURRENT_TIMESTAMP,
111)))) > (TableName.AAADPAddNoOfDates)
AND (LTRIM(RTRIM(TableName.AAADPSysOperator))) != (LTRIM(RTRIM(@UserName)))) THEN 1
ELSE 0
END AS ErrorTag
FROM TableName;