Usuário com melhor resposta
Converte tipo de Dado varchar para Numeric

Pergunta
-
Bom dia
Por favor
Estou tentando achar qual dado não está convertido, não estou conseguindo encontrar.
segue query.
select * from (
select
T1.itemcode as 'Item'
,ISNULL (T1.dscription,'') as 'Produto'
,T0.cardname as 'Fornecedor'
,T3.onhand as 'Estoque'
,T3.onorder as ' Ordem de Compra'
,CONVERT(numeric,T2.TaxRate) AS 'ImpostoIPI'
,CONVERT(numeric,T3.avgprice) AS 'Custo Item'
, CASE when t0.canceled ='n'then 'Cancelado'
else 'Aprovado'
End as Status
, CASE
when T2.TaxRate = '10.000000' then
(T3.AvgPrice*10)/100 + t3.AvgPrice
ELSE 'FORA'
END AS 'IPI_10'
,CASE
when T2.TaxRate = '15.000000' then
(T3.AvgPrice*15)/100 + t3.AvgPrice
ELSE 'FORA'
END AS 'IPI_15'
,CASE
when T2.TaxRate = '5.000000' then
(T3.AvgPrice*5)/100 + t3.AvgPrice
ELSE 'FORA'
END AS 'IPI_5'
, CASE when T4.FROZENFOR = 'N' then 'Ativo'
else 'Inatívo'
End as 'Uso_Item'
From POR1 T1
LEFT Join OPOR T0 on T1.DocEntry=T0.docentry
LEFT Join POR4 T2 on T1.DocEntry=T2.DocEntry
LEFT join OITM T4 on T1.ItemCode=T4.ItemCode
LEFT Join OITW T3 on T4.ItemCode=t3.ItemCode
Where t3.WhsCode not like '02' and t3.WhsCode not like '03'
AND t1.VatSum = (T1.Price*T1.Quantity)*T2.TaxRate /100
AND(T0.[CardName] LIKE '%EMPLAL SUDESTE EMBALAGENS PLASTICAS LTDA%'
or (T0.[CardName] LIKE '%POLO PACK EMBALAGENS PLASTICAS LTDA%')
or T0.[CardName] like 'WACO INDUSTRIA E COMERCIO DE EMBALAGENS LTDA-ME')
)
as REL
WHERE [Uso_Item] = 'Ativo'
Group by Item,Produto,Fornecedor,Estoque,[ Ordem de Compra],
[Custo Item],Uso_Item,Status,REL.ImpostoIPI,REL.IPI_5,REL.IPI_10,REL.IPI_15
Msg 8114, Level 16, State 5, Line 2
Error converting data type varchar to numeric.
Obrigado
Respostas
-
Paranhas,
A string 'FORA' é interpretada como tipo de dados VARCHAR e não NUMERIC, pois é uma string pura e não um campo.
Ao invés de retornar uma string faz um teste e coloca um retorno numérico na cláusula ELSE (Exemplo: 0.0 ou 99999.0).
Felipe Lauffer MCSA: SQL Server | MCP
Todas as Respostas
-
Paranhas,
Acredito que seja nas cláusulas CASE que utilizam aparentemente o tipo de dados NUMERIC e você está tentando retornar pela cláusula ELSE o tipo de dados VARCHAR.
Felipe Lauffer MCSA: SQL Server | MCP
-
Bom dia
Flauffer
Os dados de T3.AvgPrice e T2.TaxRate estão convertida como numeric, também FORA está numeric, e mesmo assim solicita para converter.
CASE
when T2.TaxRate = '10.000000' then
(T3.AvgPrice*T2.TaxRate) /100 + T3.AvgPrice
ELSE 'FORA'
END AS 'I10' ---COLUNAError converting data type varchar to numeric.
Obrigado
Reinaldo
-
Paranhas,
A string 'FORA' é interpretada como tipo de dados VARCHAR e não NUMERIC, pois é uma string pura e não um campo.
Ao invés de retornar uma string faz um teste e coloca um retorno numérico na cláusula ELSE (Exemplo: 0.0 ou 99999.0).
Felipe Lauffer MCSA: SQL Server | MCP
-
Flauffer
Funcionou perfeitamente, muito obrigado
, CASE
when T2.TaxRate = '10.000000' then
(T3.AvgPrice*T2.TaxRate) /100 + T3.AvgPrice
when T2.TaxRate = '15.000000' then
(T3.AvgPrice*T2.TaxRate) /100 + T3.AvgPrice
when T2.TaxRate = '5.000000' then
(T3.AvgPrice*T2.TaxRate) /100 + T3.AvgPrice
ELSE '000000'
END AS 'IPI'Obrigado
Reinaldo