Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi,I want to convert a SQL query as shown below into a stored procedure:
select namefrom namelistwhere town in ('A','B','D')
If I want to make the town as the input variable into the stored procedure, how should I declare the stored procedure? As far as I know, stored procedure could only handle individual values, and not a range of values.Thanks.
Hi,You can pass a csv string as an input parameter and use split function to convert csv to table. and use the output in your in clausehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648select namefrom namelistwhere town in (select data from dbo.split(@namecsvlist))
shallu1_gupta
Constraint Violating Yak Guru
394 Posts
Posted - 2006-02-09 : 23:14:47
specify separator as well..select namefrom namelistwhere town in (select data from dbo.split(@namecsvlist,','))