DECLARE @test INT; Truncate table #TableName SET @test = 1; SET @a = ( SELECT TableNameID FROM #TableName where (1=2)); Print @a -- result NULL SET @test = 1; SELECT @a=TableNameID FROM #TableName where (1=2); Print @a -- result 1
DECLARE @test INT; Truncate table #TableName SET @test = 1; SET @a = ( SELECT TableNameID FROM #TableName where (1=2)); Print @a -- result NULL SET @test = 1; SELECT @a=TableNameID FROM #TableName where (1=2); Print @a -- result 1