Skip to content
Advertisement

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..

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

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

Advertisement

Answer

Use a case expression instead:

case when ForeignID is not null then FirstName else SecondName end 
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement