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)
 Problem in writing Stored Procedure

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2007-06-16 : 10:37:52
Dear Friend,

I got a problem in selecting few records from a Table Using Stored Procedure.

To Select all Records we use following command
Select * from Tbl_Student

To get Selected Records we use following Sql Statement
select * from Tbl_Student where StudentId in (11,50,25,50)

Note: StudentId is an Int Column.

My query is how to Do the same task in stored procedure
by sending 11,50,25,50 as a single parameter.

With Regards

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-16 : 10:56:52
Refer this
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm


Madhivanan

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

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-06-16 : 11:48:10
also: http://www.sommarskog.se/arrays-in-sql.html


elsasoft.org
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-06-16 : 11:57:48
note that when we all start using 2008, this will be unnecessary, as table valued params are available:

https://connect.microsoft.com/SQLServer/content/content.aspx?ContentID=5507

so another alternative is just to wait a couple years.


elsasoft.org
Go to Top of Page

ranganath
Posting Yak Master

209 Posts

Posted - 2007-06-19 : 00:28:00
Hi,

Declare @str varchar(100)
Set @str = '1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24'

select * from
Tablename where ',' + @str + ',' Like '%,' + cast(columnname as varchar(100))+ ',%'

Here Columnname means which column u want to split
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-20 : 04:26:30
or

charindex(',' + @str + ',',',' + cast(columnname as varchar(100))+ ',')>0

Madhivanan

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

- Advertisement -