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

Effective LLM Prompting skills

Enable the Microsoft Power BI report file type (.pbix) in SharePoint Search