我是SQL编码的新手,到目前为止,我仅遇到一个错误代码。
在第二行WHEN CONVERT
:
({rd.254
是我的餐桌日期栏)
CASE WHEN CONVERT(date,rd.F254) Between
CONVERT(date,getdate()-7) AND CONVERT(date, getdate()-1) THEN rd.F64 END AS QtyLastWeek
WHEN CONVERT(date,rd.F254) <= CONVERT(date,getdate()-8) THEN rd.F64 END AS Qty2WeeksAgo
我正在尝试查找并修复语法。
答案 0 :(得分:2)
语法错误。如果要选择2列QtyLastWeek
和Qty2WeeksAgo
,则必须在QtyLastWeek
之后使用逗号,并使用另一个CASE
表达式。
SELECT
CASE WHEN CONVERT(date,rd.F254) BETWEEN CONVERT(date,getdate()-7) AND CONVERT(date, getdate()-1) THEN rd.F64 END AS QtyLastWeek,
CASE WHEN CONVERT(date,rd.F254) <= CONVERT(date,getdate()-8) THEN rd.F64 END AS Qty2WeeksAgo
答案 1 :(得分:2)
您缺少逗号和大小写
CASE WHEN CONVERT(date,rd.F254) Between CONVERT(date,getdate()-7) AND CONVERT(date, getdate()-1) THEN
rd.F64
END AS QtyLastWeek,
CASE WHEN CONVERT(date,rd.F254) <= CONVERT(date,getdate()-8) THEN
rd.F64
END AS Qty2WeeksAgo
答案 2 :(得分:0)
您在第二个case语句中缺少case
关键字。尝试这个 !
CASE WHEN CONVERT(date,rd.F254) Between CONVERT(date,getdate()-7) AND CONVERT(date,getdate()-1)
THEN rd.F64
END AS QtyLastWeek,
CASE WHEN CONVERT(date,rd.F254) <= CONVERT(date,getdate()-8)
THEN rd.F64
END AS Qty2WeeksAgo