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)
 Multiple update statements

Author  Topic 

paul.rowling
Yak Posting Veteran

81 Posts

Posted - 2003-10-16 : 09:42:49
Hi,

I need to update multiple columns (37 in total) in a table at the same time based on different criteria.

The table is called therapies and I want it to work as follows:

update therapies
set field1 = 'blah'
where .........X
and
update therapies
set field2 = 'blahh'
where .........X
and
update therapies
set field3 = 'blahhh'
where .........X

How do I write this in sql, please note that the where statements may need to include subqueries.

Any info will be greatly appreciated.

Cheers

Paul

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-10-16 : 09:46:39
Maybe something like :


UPDATE Therapies
SET Field1 = CASE WHEN (condition) THEN 'blah' ELSE Field1 END,
Field2 = CASE WHEN (condition) THEN 'blah' ELSE Field2 END



Does that work for you ?


Damian
Go to Top of Page

paul.rowling
Yak Posting Veteran

81 Posts

Posted - 2003-10-16 : 10:26:28
Hi Merkin,

Works excellent, thanks alot!!

Cheers

Paul
Go to Top of Page
   

- Advertisement -