我有这个查询,当我执行它时会出现以下错误。
将varchar值'I'转换为数据类型int
时转换失败
该查询用于获取帐户状态客户的报告。软件中的模块是应收账款。
SELECT *
FROM (
SELECT Id_Cliente,
TipoDeDocumento AS Id_Tipo,
iif ( TipoDeDocumento in ('1','3','4'), 'Factura', 'Nota de Credito' ) AS Tipo,
Movi_CartaPorte.Id_CartaPorte,
Movi_CartaPorte.Folio,
iif ( TipoDeDocumento in ('1','3','4'), Total, NULL) AS Cargo,
iif ( TipoDeDocumento in ('2'), Total, NULL) AS Abono,
Total,
Fecha
FROM Movi_CartaPorte
WHERE Id_StatusCartaPorte <> 100
AND 1 = 1
UNION
SELECT Id_Cliente,
1000 AS Id_Tipo,
'DEPÓSITO' AS Tipo,
Id_CartaPorte,
Descripcion AS Folio ,
NULL AS Cargo,
Importe AS Abono,
Importe AS Total,
Fecha
FROM Movi_CartaPorteCobranza
WHERE 1 = 1
) AS tabla
ORDER BY Fecha