Skip to content

Instantly share code, notes, and snippets.

@binki
Created January 16, 2015 19:20
Show Gist options
  • Save binki/bf4c4b2b2d976c000a72 to your computer and use it in GitHub Desktop.
Save binki/bf4c4b2b2d976c000a72 to your computer and use it in GitHub Desktop.
Returning 0 rows does not always mean NULL…
(1 row(s) affected)
Id Name
----------- ----
1 asdf
(1 row(s) affected)
x
------------
untouched
(1 row(s) affected)
x
------------
NULL
(1 row(s) affected)
DECLARE @x VARCHAR(12);
SELECT 1 Id, 'asdf' Name INTO #t;
SELECT * FROM #t;
SET @x = 'untouched';
SELECT TOP(1) @x = Name FROM #t WHERE Id = 0;
SELECT @x x;
SET @x = 'untouched';
SET @x = (SELECT TOP(1) Name FROM #t WHERE Id = 0);
SELECT @x x;
DROP TABLE #t;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment