Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL check if Int is null select NVarchar

I want to check if an INT is null, and if so select a different name for the value. But I keep getting a

Conversion failed when converting the varchar value ‘NAME’ to data type int

I want something like..

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ISNULL(NULLIF(ForeignID, SecondName), FirstName) AS NAME,

Simply, if null select the second name, otherwise if it has a value, select the first

>Solution :

Use a case expression instead:

case when ForeignID is not null then FirstName else SecondName end 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading