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)
 Applying update to certain columns only

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-02-04 : 06:43:54
Is there a way I could apply my update:

DECLARE @myDateField varchar(20)
SET @myDateField = 'Amended_By_Date'


UPDATE myTable
SET @myDateField =

case when @myDateField = '0' then null
when LEFT(@myDateField, 2) = '10' then '200' + SUBSTRING(@myDateField,3,LEN(@myDateField))
END

to all columns in myTable which contain the string 'date' or 'Date' as the column name?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-04 : 06:45:35
You need to use dynamic sql for this
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-04 : 06:53:58
http://www.sommarskog.se/dynamic_sql.html



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-02-04 : 07:07:24
Thanks for the link. Most informative.
Go to Top of Page
   

- Advertisement -