SQL Server - how to pass multiple value in single parameter in sql stored procedure

Asked By bhanupratap singh on 10-Mar-13 06:36 AM
how to pass multiple value in single parameter in sql stored procedure.
for Exam:- FromStation='003-JORHAT,011-SILCHAR'


DECLARE @List VARCHAR(40)
SET @List = '003-JORHAT,011-SILCHAR'
 select *from CONSIGNMENT where TOO=@List

If I give single value like @list='003-JORHAT' -- IT GIVES RESULT BUT IN ABOVE QUIERY IT DO NOT SHOW RECORDS
HOW TO DO  IT
Robbe Morris replied to bhanupratap singh on 10-Mar-13 10:16 AM
I "think" you are attempting to perform an IN clause.  TOO could contain '003-JORHAT or perhaps 011-SILCHAR

 select * from Consignment where TOO in (@List)

Assuming that is the case, you can't do this in via standard tactics in a store procedure.  You'd have to use dynamic sql and then use exec to execute the sql string.
bhanupratap singh replied to Robbe Morris on 11-Mar-13 01:06 AM
how to do it.
Kalyan Basa replied to bhanupratap singh on 16-Apr-13 05:08 AM
Bhanu,

The following query should help you.

select *from CONSIGNMENT where TOO in ('003-JORHAT','011-SILCHAR')
Thanks,
Kalyan
h b replied to Kalyan Basa on 12-Jul-13 01:53 PM
you can view this blog regarding this...

http://hiteshbhatt87.blogspot.in/