我正在用兩個Case When語句編寫查詢,第二個使用第一個的狀態來確定值。但是,第二條語句中出現無效列錯誤。有誰知道解決這個問題的簡單方法嗎?謝謝!SQL第二個病例陳述關閉第一個病例陳述的列
select
a.ID
,ss.Date
,ss.Name
,ss.Payload
,case when statusdescription = 'Bad Request' then 'Not Resolved' Else 'Resolved' End as [Error Status]
,case when
[Error Status] = 'Not Resolved' --Invalid Column issue occurring with [Error Status] here
then 'No Resolution' Else a.Date End as [Date],
,GETDATE() [Insert Date]
from #Errors a
join Table1 ss on a.id = ss.Id and a.Date = ss.Date
order by a.Date desc
case _expressions_,not _statements _... – jarlh
我剛剛做了一個我自己的測試(Sql Server 2014),並且我能夠從後續引用前面的CASE列,因此有可能(在SQL Server 2014中)。 –