Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have One SP which accept the parameter @countrycode.
the input data is like this 'IN,UK,AS,WS'

now in sp there is query like

SQL
SELECT * FROM country_master WHERE C_Code IN (@countrycode)


now i want when it executed it must be like this

SQL
SELECT * FROM country_master WHERE C_Code IN ('IN','UK','AS','WS')


For that i have replaced "," char with " ',' " . but it then IN codition taking 'IN','UK','AS','WS' as a whole value . it did not consider IN , UK , AS, WS as a separate value

i don't want to use SP_Execute functionality.
Posted
Comments
Goutam Patra 26-Nov-10 3:57am    
Check my answer again i have edited the same.

Have a look at Table valued parameters[^].

[Edit]
For SQL 2005 take you can use XML data.
Take a look at Here[^]
[End Edit]

Perhaps this will solve your purpose
 
Share this answer
 
v2
Comments
RDBurmon 26-Nov-10 3:35am    
thanks frnds can you please suggest the same solution for sql server 2005
RDBurmon 26-Nov-10 3:35am    
cause i am using sql server 2005
Dalek Dave 26-Nov-10 3:50am    
Good Answer
What about this:

SQL
declare @sqlStr varchar(500)

set @sqlStr = 'SELECT * FROM temp WHERE C_Code IN (' + @countrycode + ')'
exec (@sqlStr)
 
Share this answer
 
Comments
RDBurmon 29-Nov-10 2:35am    
Not worked
saini arun 29-Nov-10 3:22am    
Please post the code which did not work.

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