all groups > sql server programming > september 2007 >
You're in the

sql server programming

group:

dynamic column name


RE: dynamic column name Alejandro Mesa
9/25/2007 9:20:03 AM
sql server programming:
The Curse and Blessings of Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html

AMB

[quoted text, click to view]
Re: dynamic column name Jim Underwood
9/25/2007 1:17:06 PM
That would have the effect of :

select * from table where 'column1' = 'mytestdata'

In order to use dynamic column or table names, you have to use dynamic SQL,
just using variables will not work.

The link that Alejandro posted explains it in depth.

[quoted text, click to view]

dynamic column name luna
9/25/2007 5:01:06 PM
can you use something like ?

declare @column varchar(75)

select @column=('column1')

select * from table where @column='mytestdata'

I understand you can do it dynamicaly by building a sql query but was just
wondering if this way can be used

cheers

mark

AddThis Social Bookmark Button