SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    May 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with MSSQL Update using Joins

    Hi all,
    I have a spreadsheet with UPC codes and vendor product numbers, and I'm trying to run a script to update my database with that information. The UPC code is in the Item table while the Vendor product # is in the SupplierList table...thought I would be able to do a Join to link these and update the information. Maybe I thought it was too simple...?

    Code:
    update supplierlist left join supplierlist on supplierlist.itemid=item.id set supplier.reordernumber='1234' where item.itemlookupcode='test'

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    you had two errors

    first, you joined supplierlist to itself instead of to item

    second, you used mysql syntax -- mssql syntax is different
    Code:
    UPDATE supplierlist
       SET reordernumber = '1234' 
      FROM supplierlist t1
    INNER
      JOIN item t2
        ON t2.id  = t1.itemid
     WHERE t2.itemlookupcode = 'test'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    May 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    you had two errors

    first, you joined supplierlist to itself instead of to item

    second, you used mysql syntax -- mssql syntax is different
    Code:
    UPDATE supplierlist
       SET reordernumber = '1234' 
      FROM supplierlist t1
    INNER
      JOIN item t2
        ON t2.id  = t1.itemid
     WHERE t2.itemlookupcode = 'test'
    Thanks much!


Bookmarks

Posting Permissions

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