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
 General SQL Server Forums
 New to SQL Server Programming
 Updating multiple rows At once in to SQlServer2005

Author  Topic 

srinivasc_it
Starting Member

2 Posts

Posted - 2007-09-25 : 20:20:23
Hi,

I have a table called "tblProducts" with following fields:-

ProductID(Pk, AutoIncrement), ProductCode(FK), ProdDescr.

So to the above table I have added a new field/column named "ProdLongDescr(varchar, Null)"

So, I need to populate this newly added column with specific values for each row depending on "ProductCode" which is different forevery row. The problem is that I have 25 rows.So instead of Writing 25 individual update scripts, is there a way in which single query will do the same job instead of writing one update query for each row ?. If so can some one guide me how to achieve that OR point to me a good resource.

Below are a couple of Individual update scripts I Wrote. "ProductCode" is different for all 25 rows.

Update tblValAdPackageElement SET ProdLongDescr = 'Slideshows' WHERE ProductCode = 'SLID'
And szElementDescr='Slideshow'
if @@error <> 0
begin
goto ErrPos
end

Update tblValAdPackageElement SET ProdLongDescr = 'CategorySlideshows' WHERE ProductCode = 'SLDC'
And szElementDescr='CategorySlideshow'
if @@error <> 0
begin
goto ErrPos
end

Thanks,

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-25 : 22:30:01
What is the source for ProdLongDescr? Is there any look up table from where you can get the ProdLongDescr based on a given ProductCode?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-26 : 05:57:14
[code]
Update tblValAdPackageElement
SET ProdLongDescr =
CASE WHEN ProductCode = 'SLID' And szElementDescr='Slideshow' THEN 'Slideshows'
WHEN ... THEN ...
ELSE 'Long Description not Set Up Yet'
END
[/code]
Kristen
Go to Top of Page
   

- Advertisement -