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 2005 Forums
 Transact-SQL (2005)
 Set Column name from declare value

Author  Topic 

PBoy
Starting Member

22 Posts

Posted - 2012-03-13 : 10:08:29
Hi All,

Is it possible to set the column name on a update/insert statement from a declared value?

for example:

declare @blinky varchar(50)
set @blinky = Datename(dw,Getdate())
print @blinky

UPDATE boo_table
SET @blinky = '22222'
WHERE column_1 = 'boo'

The column names are the days of the week.

Any help would be great :)

Cheers
P

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 10:17:18
This is interesting for you:
http://www.sommarskog.se/dynamic_sql.html


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -