通过比较值,我在投射CurrRunDate时遇到问题。
SELECT
s.Cid,
s.MobileNo,
AvailableBalance = (SELECT dbo.GetAvailBalAmt(acc,0)/100 FROM SMSCIF),
b.CurrRunDate,
s.CreatedDate,
s.ExpiryDate,
CAST (CASE WHEN
b.CurrRundate < s.ExpiryDate THEN '00'
ELSE '01'
END) AS RenewStatus
FROM
SMSCIF s
LEFT JOIN
BRPARMS b ON s.br = b.br
WHERE
(CAST(s.CreatedDate AS DATE) = b.CurrRundate AND s.status = '00')
OR Cast(s.ExpiryDate As Date) = b.CurrRundate
错误消息:“投放”附近的语法不正确,预期为“ AS”。
答案 0 :(得分:1)
您需要CAST( (CASE expression) AS VARCHAR(2))
,当前查询有语法错误。
将其更改为下面的查询将起作用:
CAST ((CASE WHEN b.CurrRundate < s.ExpiryDate THEN '00'
ELSE '01' END)
AS VARCHAR(2)) AS RenewStatus,
答案 1 :(得分:0)
为表达式分配别名不需要CAST
;删除CAST
:
CASE
WHEN b.CurrRundate < s.ExpiryDate THEN '00'
ELSE '01'
END AS RenewStatus