x

How to pass a CSV to a stored procedure for an IN statement

                    
declare @Table1 table (RegNo int, RegName varchar(10))                    
insert into @Table1                    
select 55,'James'                    
union select 56,'Frank'                    

Now i need to fetch records through Stored Procedure like following

                    
CREATE PROCEDURE [dbo].[Sp_FindNo]                    
@RegNo int                    
As                    
Select RegName from Table1 where RegNo in (@RegNo)                    
GO                    

Now the problem is like if i do the following then an error displays


EXEC Sp_FindNo '55,56'
or
EXEC Sp_FindNo 55,56
more ▼

asked Jan 31, 2010 at 01:52 AM in Default

Deepak Ghosh gravatar image

Deepak Ghosh
12 2 2 2

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first
more ▼

answered Jan 31, 2010 at 03:15 AM

Squirrel 1 gravatar image

Squirrel 1
1.6k 1 3

Thanks dear....its done.....great help.....
Feb 02, 2010 at 03:11 AM Deepak Ghosh
(comments are locked)
10|1200 characters needed characters left

If you were using SQL 2008 you could pass a Table to a Stored Procedure

more ▼

answered Jan 31, 2010 at 07:24 AM

Kristen gravatar image

Kristen ♦
2.2k 6 7 10

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1944
x407
x35

asked: Jan 31, 2010 at 01:52 AM

Seen: 2044 times

Last Updated: Jan 31, 2010 at 03:09 PM