クエリに日時列があり、このクエリでCASEを実行したいと思います。
DateDelivered列がnullでない場合は、日付を表示します。それ以外の場合は、文字列「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