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.

Comments

Popular posts from this blog

Top JavaScript courses helping you develop SPFx webPart with ReactJS and AngularJS

React Native error - Cannot find module 'metro-react-native-babel-preset'

Effective ChatGPT Prompt Writing Tips