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
 Transact-SQL (2000)
 Parametrized queries that do not work.

Author  Topic 

antogonzal
Starting Member

1 Post

Posted - 2004-10-26 : 03:30:01
Hi all,

Anyboy has got a way to parametrize a column so that it was possible to asign an external value to its name ?
For example in an UPDATE example like this:


UPDATE Table
SET columm_name = newdata
WHERE ( another_column = 'whatever')

instead of using column_name, passing it as a parameter, like this:

@variable VARCHAR (20)

UPDATE Table
SET @variable = newdata
WHERE ( another_column = 'whatever')

if you try to pass column_name as a parameter to @variable, it would not work at all.

Is there any way of making this idea work ?

There would be lots of uses for it, like converting colums to rows in a parametrized way, etc...


Thanks !

Regards

Toni

nr
SQLTeam MVY

12543 Posts

Posted - 2004-10-26 : 03:37:01
declare @sql varchar(1000)
select @sql = 'update table set ' + @columnname + ' = ''whatever'' where anothercolumn = ''whatever'''
exec (@sql)

>> There would be lots of uses for it
Not really - usually a sign of poor design.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -