Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanueltissera/5901559 to your computer and use it in GitHub Desktop.
Save emmanueltissera/5901559 to your computer and use it in GitHub Desktop.
Transact SQL for SQL 2008 and above to work with a integer array like structure
ALTER PROCEDURE getNodes
@isActive bit
AS
BEGIN
-- Declare a single column table to be used as a single dimension array
DECLARE @activeNodes TABLE (id int)
-- Only if the following condition is satisfied, 1070 will be added to the pseudo-array
IF @isActive = 1
INSERT INTO @activeNodes(id) VALUES (1070)
-- 1067 and 1069 will be anyhow added in one statement (SQL 2008 and higher) to the pseudo-array
INSERT INTO @activeNodes(id) VALUES (1067), (1069)
-- Now an IN clause could be used, really useful in more complex queries
SELECT [nodeId], [xml]
FROM [cmsContentXml]
WHERE [nodeId] IN (SELECT id FROM @activeNodes)
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment