SQL Server : conversion error numeric to varchar case

若如初见. 提交于 2021-02-11 08:02:53

问题


I have this query:

CASE ClaimsFees.TBA 
   WHEN 0 THEN CAST(IndemnityReserve AS NUMERIC(9,2)) 
   ELSE 'TBA' 
END AS 'Reserve Indemnity'

but I always get this error:

Error converting data type varchar to numeric

I have tried to convert TBA as numeric but I can't do this, I also can't convert all the results to varchar because when I transfer to Excel file the number 1.325,27 becomes 132.527,00 with the ##,##0.00 format.

Is there a method in SQL Server that I can use to solve this?


回答1:


The column can only have one type, and as 'TBA' can only be a string, you'll need to make the numeric a string too.

CASE ClaimsFees.TBA WHEN 0 
then cast(cast(IndemnityReserve as NUMERIC(9,2)) as varchar(12))
else 'TBA' 
end as 'Reserve Indemnity',


来源:https://stackoverflow.com/questions/28672358/sql-server-conversion-error-numeric-to-varchar-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!