Search code examples
sqlstored-proceduresisnullssms-2012

Need to concatenate to a field value, after checking if value [isnull]


I have a stored procedure where I'm pulling data from a table. The value in the field can either be NULL or a number value (ex: 15).

I am hoping to display this value with a $, however I'm finding it a little hard to do that, since I'm checking if the fieldvalue isnull, if it is, I am setting value to 0.0. This is what it looks like.

''Amount Paid''= isnull(tbl_A.AmountPaid,''0.0'')

is there an alternative way to do this so that tbl_A.AmountPaid is displayed with $ in front of it if it isn't NULL?

sample data : 93.39
I would like to display it as $ 93.39 once it's checked that the value is not NULL


Solution

  • You can use something like below to add the $ sign before the amount. In this way, $ sign will show for both case if values are there or NULL.

    SELECT '$ '+CAST(ISNULL(tbl_A.AmountPaid,0.0) AS VARCHAR)