-
Column name in Variable for select list
I am dynamically trying to pass a particular column name to the select list of a select statement.
that is
@var = 'Col1'
so I need the following query
select col1 from tbl1
I will not know the column name is 'Col1' but the value will be in @var. How can I use it?
By the way I am using SQL Server 2000
-
You should build your SELECT statement in a variable like
declare @cmdstr varchar(100)
set @cmdstr = 'select ' + @var + ' from table1'
exec (@cmdstr)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|