Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dear sir/Madam,

iam having where condition in SQL query . in where condition if the location is 10 then it should get 10,15,20 id's how to pass these three variables

Regards
dhana
Posted
Comments
_Amy 17-Jun-13 5:58am    
Your question is not clear. Click on Improve question and provide more information and code blogs.
Prasad_Kulkarni 17-Jun-13 6:01am    
Please post your sql query.

You can try IN Operator[^] in SQL Server. Try this:
SQL
SELECT * FROM TableName WHERE LocationID IN(10, 15, 20)

Refer the link below for more information:
http://www.w3schools.com/sql/sql_in.asp[^]


--Amit
 
Share this answer
 
Hi,
In your case you have to use Dynamic Query... for example
SQL
-- Your SP variable : @LocIDs VARCHAR(100)
CREATE PROCEDURE ProListLoc
@LocIDs VARCHAR(100)
AS 
BEGIN 
   DECLARE @SqlQuery VARCHAR(1000)

   SELECT @SqlQuery='SELECT * FROM TableName WHERE LocationID IN('+ @LocIDs +')'
   PRINT @SqlQuery
   EXEC (@SqlQuery)
END
-- then you will get the details based on your Input to SP.
EXEC ProListLoc @LocIDs = '10,15,20'

Regards,
GVPrabu
 
Share this answer
 
v2

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