I have a string variabled declared as so:
declare @myGeniuses as nvarchar(8000);
set @myGeniuses = ' in (1,2,3)';
I want to apply my variable in a select statement like so:
select * from GENIUSES where GeniusId @myGeniuses
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You will need to use sp_executesql to achieve that result which lets you pass in your query statement as a string and executes it.
See this for more details: http://msdn.microsoft.com/en-us/library/ms188001.aspx
Example usage: