我的查询中有一个日期时间列,我想在这个查询中做一个 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