SQL – Simple test for null return with SELECT to variable
This quick example shows how to return the result of a query to a variable, and to show the value, checks to see if the value is NULL or not.
DECLARE @checkForX varchar(15)
SELECT @checkForX = [IPAddress]
FROM [TestRunTracker].[dbo].[IPAddrMachNameRunStatus]
WHERE [IPAddress] = '10.222.52.57'
PRINT @checkForX
IF @checkForX IS NULL
PRINT 'checkForX is NULL'
ELSE
PRINT 'checkForX is NOT NULL'
No comments:
Post a Comment