Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Column name as parameter in the t-sql query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-02-28 : 07:49:42
thankforhelp writes "I need help in parametization of column name.

declare @temp_col varchar(50)
set @temp-_col = 'employee_name' -- this going to be stored procedure parameter

select * from
master m
where m.@temp_col is not null

So everytime I can change the column name and run the same stored procedure. This just example I can't give the actual query has it is part of a big system.

Thanks for the help."

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-02-28 : 08:16:28

Try this


declare @temp_col varchar(50)
set @temp_col = 'employee_name'
Exec('select * from master m where m.'+@temp_col+' is not null')



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-02-28 : 08:34:42
Hope you have good security on your database, because this will open you up to all kinds of hacking.
Go to Top of Page
   

- Advertisement -