Why does this return 'do nothing' when I have set the variable @CompName to NULL? I have a table Company that does not have a NULL Compname or a empty Compname in it (I've triple verified).
DECLARE @CompName varchar(70)=NULL
IF EXISTS (SELECT Company FROM Company WHERE Compname=coalesce(@CompName,''))
print 'Do Nothing'
I've also tried IF EXISTS (SELECT * FROM Company WHERE @CompName is not null and Compname=@CompName)
and it still returns 'do nothing'
I ultimately am doing an insert into the Company table but do not want to do an insert if the CompName already exists or if CompName is null