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)
 Flexible UPDATE stored procedure

Author  Topic 

sosh
Starting Member

2 Posts

Posted - 2007-12-13 : 10:50:59
Hi,

This may be a bit of a stupid question - I've been away from SQL for a couple of years now.

But...

What's the best way to create a stored procedure that updates a row (given an ID), and also updates any or all of the columns based on the parameters passed to it?

e.g. The same sp might be used to update just one column in a row, or all of them.

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-13 : 11:02:09
something like this

update t
set cola = coalesce(@cola, cola),
colb = coalesce(@colb, colb),
. . .
from yourtable t
where id = @ID



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sosh
Starting Member

2 Posts

Posted - 2007-12-13 : 13:03:43
perfect, thanks!
Go to Top of Page
   

- Advertisement -