T-SQL: Conver null or empty string to numeric value
I tried to use sum for a "varchar" type column in SQL table, and one day the code has error as there is a line contains empty value in this column and so the sum() function not working anymore.
So I add following function NULLIF(<clumn>,0)
The whole sum function is as below:
sum(CAST(NULLIF(AMOUNT,0) AS DECIMAL(22,2)))
Now I can get the sum amount value successfully.
So I add following function NULLIF(<clumn>,0)
The whole sum function is as below:
sum(CAST(NULLIF(AMOUNT,0) AS DECIMAL(22,2)))
Now I can get the sum amount value successfully.
Comments
Post a Comment