Home > other >  SQL check if Int is null select NVarchar
SQL check if Int is null select NVarchar

Time:01-21

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

CodePudding user response:

Use a case expression instead:

case when ForeignID is not null then FirstName else SecondName end 
  •  Tags:  
  • Related