Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all,

I have pass comma separated parametor to Stored procedure but i don't get result,

E.g.
SQL
@status_code='1','2';


and I have replace it in SP like

SQL
tof.case_status in(convert(varchar(max),@status_code))


but i don't get result,

please tell me where i am wrong
Posted
Comments
joshrduncan2012 28-Nov-12 9:02am    
What result are you getting and what should you be getting? Can we see more of your code to get an idea of the context of how this is implemented? We can't assume anything based on what you have shown us already.
Maksud Saifullah Pulak 28-Nov-12 14:44pm    
What result you are getting now?
[no name] 28-Nov-12 17:27pm    
have you ever heard of a subquery?
madhuri@mumbai 29-Nov-12 2:31am    
Hey ,guys I have solved this problem.

1 solution

Basic information, you'll find here: http://msdn.microsoft.com/en-us/library/ms177682.aspx[^]

Below, example code should works:
SQL
CREATE TABLE #tof(case_status INT)

INSERT INTO #tof(case_status)
VALUES (1)
INSERT INTO #tof(case_status)
VALUES (2)
INSERT INTO #tof(case_status)
VALUES (3)
INSERT INTO #tof(case_status)
VALUES (4)
INSERT INTO #tof(case_status)
VALUES (5)

DECLARE @status_code NVARCHAR(300)
DECLARE @sql_query NVARCHAR(300)

SET @status_code='1, 2'
SET @sql_query = 'SELECT * ' +
                'FROM #tof ' +
                'WHERE case_status IN (' + @status_code + ')'
EXEC (@sql_query)

DROP TABLE #tof
 
Share this answer
 
Comments
madhuri@mumbai 29-Nov-12 2:33am    
thanks buddy,
I have apply same as your solution only the littlebit difference,in mine and your solution.but thanks.
madhuri@mumbai 29-Nov-12 4:01am    
hi,
I have solve this problem for varchar,I have the problem in,
my parametor is varchar and DB type is Int so what i do in that case,
actually I have cast it but it throw conversion error.
Maciej Los 29-Nov-12 14:18pm    
And...
madhuri@mumbai 30-Nov-12 0:42am    
And... what do you mean sir... I don't understand
I am telling you my problem,but anyway I have solved it.
thanks..
Maciej Los 30-Nov-12 12:43pm    
Thank you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900