Search code examples
sql-servert-sqlcoalesce

Coalesce NULL to '-' in a Float data type column - TSQL


I have a calculated column Total_Count which is derived from couple of float data type columns with results like 0, 101, NULL (in Total_Count column).

Instead of showing NULL I want to show - (hyphen character) in the Total_Count column.

If I use COALESCE(Total_Count, '-') then I am getting the following error:

Msg 8114, Level 16, State 5, Line 62

Error converting data type varchar to float.

Please help!


Solution

  • try this in select

    SELECT COALESCE(CAST(Total_Count AS VARCHAR), '-')