Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002
    Posts
    2

    Unanswered: Update across two tables

    Sorry for the simple question, but can't find any info on this.

    I have two tables named OLD1 and NEW1. Each has a price field (nvarchar, 50). I am trying to update the price in NEW1 with the pricing in OLD1. How do I do this? It seems SQL won't let me specify more than one table. In mysql you could do this (with the newest version).

    Thanks,
    Duck

  2. #2
    Join Date
    Dec 2002
    Posts
    2

    Re: Update across two tables

    Originally posted by duck
    Sorry for the simple question, but can't find any info on this.

    I have two tables named OLD1 and NEW1. Each has a price field (nvarchar, 50). I am trying to update the price in NEW1 with the pricing in OLD1. How do I do this? It seems SQL won't let me specify more than one table. In mysql you could do this (with the newest version).

    Thanks,
    Duck
    Nevermind. I found out that I need to use a CURSOR and that works great. Thanks.

  3. #3
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249

    Re: Update across two tables

    --You did not specify PK, but you probably need this:

    update NEW1 set
    NEW1.price=OLD1.price
    from NEW1
    join OLD1
    on NEW1."id"=OLD1."id"

    --See topic UPDATE(described) in BOL
    Last edited by ispaleny; 12-30-02 at 19:15.

Posting Permissions

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