Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to write this in a Stored Proc?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-10-05 : 07:21:50
Kavita writes "How can I pass an input list of strings to the stored proc? The below is NOT working for me...If you can answer this question, I would be grateful to you.


CREATE PROCEDURE MyProc
@NameList varchar(500)

AS

BEGIN

SET NOCOUNT ON

SELECT MyName from MyTable where MyName in (@NameList)

END

Go"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-05 : 07:33:48
One of the ways is to use Dynamic SQL

Exec('SELECT MyName from MyTable where MyName in ('+@NameList+')')

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-10-05 : 10:11:39
hey Kristen, another sticky topic for you...
located at the newbie forum

ways:
1. use charindex or patindex to check the pattern
2. use a function that will split the text you provided


--------------------
keeping it simple...
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-10-05 : 10:23:53
Search the site...there are tons of article

http://www.sqlteam.com/item.asp?ItemID=11499


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-10-05 : 13:40:27
"another sticky topic for you"

I've got one "SLECT * FROM MyTable WHERE MyColumn IN @CSV" in there, but I don't think that thread is very good - doesn't cover SPLIT etc. I could do with a 10-out-of-10 thread to link to

Kristen
Go to Top of Page
   

- Advertisement -