sql - Can I combine multiple update statements while keeping functionality? -


i'm going through stored procedure , trying optimize when came across 13 update statements similar below. wondering if had better solution this. know can use case statements or coalesce , semantically same, bear in mind of columns updated. won't cause problems, may have high transactional volume approach cause concurrency issues.

update  cogs set     revenue = 0   revenue null         , monthdate = @targetcogsdate;  update  cogs set     costs = 0   costs null         , monthdate = @targetcogsdate;  update  cogs set     disposal = 0   disposal null         , monthdate = @targetcogsdate;  update  cogs set     trans = 0   trans null         , monthdate = @targetcogsdate; 

yes, use coalesce():

update cogs     set revenue = coalesce(revenue, 0),         costs = coalesce(costs, 0),         disposal = coalesce(disposal, 0),         trans = coalesce(trans, 0)     monthdate = @targetcogsdate ,           (revenue null or costs null or disposal null or trans null); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -