Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2007
    Posts
    3

    Unanswered: Updating multiple rows At once in to SQlServer2005 Table

    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,

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Sure, you could write this using a single update statement and a long-ass CASE statement with 25 different evaluations, but I don't see how that is really preferable to 25 separate updates.
    And this is a one-time update? For just 25 rows? My question would be why you care.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •