Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2005
    Posts
    266

    Unanswered: Update From Select

    Hi

    how can you update many fields from a select ? :


    UPDATE table1 (a1,b1,c1) SELECT (a2,b2,c2) FROM table2 WHERE table1.id = table2.id


    for MS SQL 2000/25000

    thank you for helping

  2. #2
    Join Date
    Dec 2005
    Posts
    266
    if there is not a better method I think I got it :

    UPDATE table1
    SET a1=a2,b1=b2,c1=c2
    FROM table1 INNER JOIN table2 WHERE table1.id = table2.id

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    How does this fair for you?
    Code:
    UPDATE table1
    SET    field1 = t2.field1
         , field2 = t2.field2
         , fieldN = t2.fieldN
    FROM   table1 t1
     INNER
      JOIN table2 t2
        ON t1.id = t2.id
    George
    Home | Blog

  4. #4
    Join Date
    Dec 2005
    Posts
    266
    yes it works fine

    thank you

Posting Permissions

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