我的查詢中有一個日期時間列,我想在此查詢中執行一個CASE。使用DateTime列的CASE語句
如果DateDelivered列不爲空,則顯示日期,否則顯示字符串'Pendent' 我該怎麼做?
CASE WHEN DateDelivered IS NOT NULL THEN DateDelivered ELSE 'Pendent' END AS DateDelivered 2
我得到這個錯誤
Conversion failed when converting date and/or time from character string.
SELECT San_Imovel.Imovel_Id ,
San_Chave.DataHoraPegou ,
CASE WHEN San_Chave.DateDelivered IS NOT NULL THEN San_Chave.DateDelivered
ELSE ISNULL(CAST(San_Chave.DateDelivered AS VARCHAR), 'Pendent')
END AS DateDelivered2 ,
San_Usuario.NomeCompleto + ' - ' + sc.Apelido AS Nome ,
San_Cliente.NomeCompleto AS NomeCliente ,
San_Credenciada.Apelido ,
San_Cliente.Cliente_Id ,
San_ChaveImovel.QuantidadeChave
FROM San_ChaveImovel
JOIN San_Chave ON San_ChaveImovel.Chave_Id = San_Chave.Chave_Id
JOIN San_Credenciada ON San_Chave.Credenciada_Id = San_Credenciada.Credenciada_Id
JOIN San_Imovel ON San_ChaveImovel.Imovel_Id = San_Imovel.Imovel_Id
JOIN San_Usuario ON San_Chave.Usuario_Id_Responsavel = San_Usuario.Usuario_Id
JOIN San_Credenciada sc ON San_Usuario.Credenciada_Id = sc.Credenciada_Id
JOIN San_Cliente ON San_Chave.Cliente_Id = San_Cliente.Cliente_Id
什麼是整個查詢? – 2012-04-26 16:52:47
@mostymostacho更新 – 2012-04-26 17:00:32