Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does sql evaluate ISNUMERIC(ISNULL(VALUE, 'blah'))

Tags:

t-sql

My assumption was that it would return a true if that value was numeric (within the isnumeric range) but FALSE if the ISNULL returns 'blah'. Seems like my assumption was off...

I'm using the it in the following way

case when ISNULL(ISNUMERIC(c.npinumber), 'blah') = 1
       then c.NPiNUmber
     else 'not valid: ' + c.NpiNumber
     end as npi 
like image 883
Michael Avatar asked Dec 02 '25 09:12

Michael


1 Answers

Building on Dhruvesh's answer,

case
    when ISNUMERIC(c.npinumber) = 1 then c.NPiNUmber
    else 'not valid: ' + c.NpiNumber
end as npi

Will produce NULL anytime NpiNumber is NULL. The reason is that NULL + any string will still return NULL. The solution is to simply use the COALESCE function

case
    when ISNUMERIC(c.npinumber) = 1 then c.NPiNUmber
    else 'not valid: ' + COALESCE(c.NpiNumber, 'NULL VALUE')
end as npi
like image 155
Adam Rackis Avatar answered Dec 03 '25 22:12

Adam Rackis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!