all groups > sql server new users > september 2006 >
You're in the

sql server new users

group:

problem with IN in stored proc



Re: problem with IN in stored proc Arnie Rowland
9/28/2006 4:22:27 PM
sql server new users: This is a common issue where folks are attempting to use a varchar parameter
to simulate an array().

If you need to do handle a parameter as an array (and SQL Server does NOT
support array() datatypes, then these articles may be useful to you.

Arrays and Lists in SQL Server
http://www.sommarskog.se/arrays-in-sql.html
http://www.realsqlguy.com/?p=9
http://www.aspfaq.com/2248
http://realsqlguy.com/twiki/bin/view/RealSQLGuy/ParseDelimitedStringToTable
2005-
http://omnibuzz-sql.blogspot.com/2006/06/interesting-queries-using-recursive.html


--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc


Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


[quoted text, click to view]

problem with IN in stored proc Daves
9/28/2006 11:02:43 PM
I parse a querystring from a .net website into a stored proc;

ALTER PROCEDURE Postlists_CreateList
(
@Groups varchar(255) = NULL
...
)
AS

INSERT INTO Postlists_Recipients (PostlistID,UserID)
SELECT @PostlistID, UserID
FROM UsersInGroups
WHERE UsersInGroups.GroupID IN (@Groups)

Well it works fine until @Users contains comma seperated values, the idea
was that this sp would be able to take multiple recipients this way but
obviously Sql server complains because the datatypes aren't the same
(GroupID is int, @Groups is varchar)... if you get my point do you know of
any solution besides
WHERE CAST(UsersInGroups.GroupID AS varchar(5)) IN (@Groups)

which is very "clumsy"??

Re: problem with IN in stored proc Hugo Kornelis
9/29/2006 1:18:51 AM
[quoted text, click to view]

..... and wouldn't work either.

Check out http://www.sommarskog.se/arrays-in-sql.html

--
AddThis Social Bookmark Button