Im trying to return the results of a query into a variable to I am able to use it in a insert statement. However my select keeps returning null even though I believe I have the ISNULL(NULLIF()) set up correctly.
declare @test varchar(10)
set @test = (select ISNULL(NULLIF(discnumber,''),'NA')
from discmaster
where meteredfilename = '3501' or nonmeteredfilename='3501')
select @test
It seems correct but still returns a NULL value. Would you Select Case but not 100% sure on that method either.
I’d move the
ISNULLoutside of the subquery – what if the subquery returns no results?(I’ve also been a snob and replaced
ISNULLwithCOALESCE. Outside of a few scenarios,COAELSCEis the better function).