1
我使用下面的查詢,但得到的錯誤設置CASE語句,以便所有的結果類型爲VARCHAR
'Conversion failed when converting the varchar value '8-14' to data type int.'
我相信它,因爲第二行是返回一個整數,其餘的不是,是正確的?
我不打算計算這個字段,所以如果他們都需要是相同類型的值,讓第二行返回爲varchar會很好。我嘗試過使用'convert',但是我不想我認爲我的語法沒錯。
,(case when AppointmentCancellationDate = null Then 'NoDate'
when (datediff(day,BasicStartDate,AppointmentCancellationDate)) < '8' then (datediff(day,BasicStartDate,AppointmentCancellationDate))
when (datediff(day,BasicStartDate,AppointmentCancellationDate)) <15 then '8-14'
when (datediff(day,BasicStartDate,AppointmentCancellationDate)) <22 then '15-21'
Else '+22' end) as CancWindowGroup
感謝看起來像它的工作 –
並從'<'8''更改爲'<8' –
並將'= null'更改爲'爲空' – TriV