Paul Michaels
Paul Michaels

Reputation: 16705

Using COALESCE with numeric values

I have the following code:

set @mystring = coalesce(numericval,'');

What I want is the following behaviour:

I can't coelesce this to a numeric value, because that value will be output, and I can't convert it while it's null.

How can I achieve this?

Upvotes: 0

Views: 6871

Answers (1)

Amit Singh
Amit Singh

Reputation: 8129

Try this

  Declare @mystring as varchar(Max)
    set @mystring = coalesce(Cast(numericval as varchar),'');
    Select @mystring

Upvotes: 1

Related Questions