October 19, 2010 at 2:17 pm
Hi all
Is there any way that I can pass the column names in where clause and select them.
like
select * from employee
where column_name in (age,salary)
this shows me only Age and salary from the Employee table.
any help on this.
Thanks [/font]
October 19, 2010 at 2:22 pm
Learner1 (10/19/2010)
Hi allIs there any way that I can pass the column names in where clause and select them.
like
select * from employee
where column_name in (age,salary)
this shows me only Age and salary from the Employee table.
any help on this.
Don't you just want
select age,salary from employee
?
Or if the list of columns to show must be dynamic (from a variable/parameter), you'll need to use dynamic sql.
October 19, 2010 at 2:41 pm
yes, it is dynamically passed ,the list of column is passed through a parameter
it is dynamic sql, Can be any column in the table like Age ,Salary, Name, Address, Phone, City.........
Thanks [/font]
October 19, 2010 at 7:06 pm
Learner1 (10/19/2010)
yes, it is dynamically passed ,the list of column is passed through a parameterit is dynamic sql, Can be any column in the table like Age ,Salary, Name, Address, Phone, City.........
Ok, the way to do that then is to build your query as a string variable and use either EXEC or sp_executesql (which will let you parameterize it) to run the query in your string. If you search "dynamic sql" on the forums, you'll find some examples that will give you the idea.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply