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.
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