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)
 Update only selected Fields in a Table

Author  Topic 

BrianBurgit
Starting Member

12 Posts

Posted - 2005-12-30 : 13:07:05
I have a Table with 10 Fields and at any given time some or all of them may need to be updated. What's the best way to do this? I know I can create my sql statement in code based on what Fields need updating, but I'm hoping there's an easier way.

Thanks,

BB

SamC
White Water Yakist

3467 Posts

Posted - 2005-12-30 : 14:33:55
[CODE]UPDATE Mytable
SET
Col1 = IsNull(@NewCol1, Col1),
Col2 = CASE WHEN condition THEN @NewCol2 ELSE Col2 END ,
Col3 = COALESCE(@Val1, @Val2, @Val3, Col3)
[/CODE]
Go to Top of Page

BrianBurgit
Starting Member

12 Posts

Posted - 2005-12-30 : 14:38:58
Thanks SamC!
Go to Top of Page
   

- Advertisement -