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

I wanted to know if it is possible to concatenate a string as where condition in sql2008, the string must also include the column name(s) of the table for which i am using the where condition. I tried it but was not successful! does anyone know how i can do this?

Thanks and Regards
Posted
Comments
Prerak Patel 12-Jul-11 3:12am    
Not clear. Elaborate more or show us sample query.
Uday P.Singh 12-Jul-11 4:17am    
post your query, so that we can help you.
Roliking 12-Jul-11 4:31am    
the query is something like this, the statement that i want to execute is a string which is dynamically created


declare @Fil as varchar(100)
set @Fil= 'from tbl_Accountmaster'
select + @Fil

Can you use like this? -
SQL
declare @Fil as varchar(100) set @Fil= '* from yourTable' ;
declare @qury as varchar(200) set @qury='Select ' + @Fil
exec (@qury)
 
Share this answer
 
v4
Comments
nthaomei 12-Jul-11 5:21am    
Please make me known if it is helpful.
Roliking 12-Jul-11 8:22am    
Thanks it was helpful! I found out one more way to do it using sp_executesql
which is similar to exec()

Thanks anyways...
Some good info on dynamic where clauses at Implementing Dynamic WHERE-Clause in Static SQL[^].
 
Share this answer
 
It would be helpful if you provide a piece of code containing the query.
 
Share this answer
 
Comments
Roliking 12-Jul-11 4:30am    
the query is something like this, the statement that i want to execute is a string which is dynamically created


declare @Fil as varchar(100)
set @Fil= 'from tbl_Accountmaster'
select + @Fil

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