我想按照
的方式进行选择CASE
WHEN Status = 'Live'
THEN
WHEN BookingDate = LastModifiedDateTime
THEN
'New'
ELSE
'Modified'
ELSE
Status
END AS s
我遇到了第二个WHEN
关键字' WHEN'附近的语法不正确。
我不确定如何解决这个问题?
答案 0 :(得分:5)
您无法嵌套WHEN
,您可以嵌套CASE
:
CASE
WHEN Status = 'Live'
THEN
CASE WHEN BookingDate = LastModifiedDateTime
THEN
'New'
ELSE
'Modified'
END
ELSE
Status
END AS s
就个人而言,我会这样写:
CASE
WHEN Status = 'Live' AND BookingDate = LastModifiedDateTime
THEN 'New'
WHEN Status = 'Live'
THEN 'Modified'
ELSE Status
END AS s