SQL Server Quick Workaround To Declare Arrays

Writing by on Tuesday, 18 of March , 2008 at 5:11 pm

Need a quick workaround to declaring arrays in SQL Server?

-- Trying to accomplish something like this?
int[] @list = {1864, 1966} -- INCORRECT SQL 
SELECT * FROM Employees
WHERE id IN @list

Here’s a workaround

DECLARE @list TABLE (id int)          -- create an int[] "array"
INSERT @list VALUES (1864)            -- hardcode values
INSERT @list VALUES (1966)            -- hardcode values
SELECT * FROM Employees               -- my query
WHERE id IN (SELECT id FROM @list)    -- use the int[] array

Leave a comment

Category: SQL DB

No Comments

No comments yet.

Leave a comment

You must be logged in to post a comment.

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.