April 28, 2005 at 3:10 pm
Hi Guys! i hope ya can help me...
(using SQL Server 2000)
I have a Stored Proc and would like to pass in a VARCHAR parameter (as a comma delimited list). The problem is that the query will need to use it in a IN clause...
DECLARE @PARAM AS VARCHAR(20)
SET @PARAM = 'Dan', 'Mike', 'Lisa' <--this wont work
SELECT *
FROM Orders
WHERE Name IN (@PARAM)
is there a away around this? thanks for the help
There are ll types of people: those who understand Roman Numerals, and those who do not.
April 28, 2005 at 4:34 pm
Look at this posting: "Need trigger to split 1 filed to 4 (Pages 1 2 3 ) "
It is long and I have some knuckleheaded comments, but a number of people gave some very good suggestions.
I wasn't born stupid - I had to study.
April 28, 2005 at 4:35 pm
ok i finally found 2 good and valid solutions.
1) http://www.sommarskog.se/arrays-in-sql.html
2)
DECLARE @Var AS VARCHAR(100)
SET @Var = '''Dan'', ''Mike'', ''Lisa'''
DECLARE @SQL AS varchar(1000)
SET @SQL = 'SELECT*
FROM ORDERS
WHERE
NAME IN (' + @Var + ')'
Exec(@SQL)
There are ll types of people: those who understand Roman Numerals, and those who do not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply