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)
 How to qualify variables as database object name, like column name?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-27 : 09:17:42
Terry writes "I am doing a stored procedure, within it I need to update hundreds of columns, I tried to use variables to loop to update the columns , like the code below("@ExportTo_RollupOrder is the numeric string "1", "2",...):
----------------------------------------------------------
select @ExportTo_ColumnName="Q"+@ExportTo_RollupOrder
update EriExport
set @ExportTo_ColumnName = @ExportTo_Numeric
where base_id= @DistinctUser
----------------------------------------------------------

but it did not work, please give me a hand! Thanks!"

dsdeming

479 Posts

Posted - 2002-06-27 : 09:37:01
If you need to use a variable for the column name in the SET clause, it's going to require dynamic SQL. See sp_executesql and EXECUTE in BOL.

Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-06-28 : 20:14:24
Or read these great articles on Dynamic SQL here on SQLTeam...

[url]http://www.sqlteam.com/item.asp?ItemID=4599[/url]
[url]http://www.sqlteam.com/item.asp?ItemID=4619[/url]

Go to Top of Page
   

- Advertisement -