Skip to content

Instantly share code, notes, and snippets.

@emmanueltissera
Created July 1, 2013 14:54
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/5901542 to your computer and use it in GitHub Desktop.
Save emmanueltissera/5901542 to your computer and use it in GitHub Desktop.
Transact SQL for SQL 2005 to work with a integer array like structure
CREATE 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 to the pseudo-array
INSERT INTO @activeNodes(id) VALUES (1067)
INSERT INTO @activeNodes(id) VALUES (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