0

I used the following script to populate a table. This script worked just fine:

insert into TSC_Intermediate.dbo.stock 
                (article
                , description
                , article_id
                , client
                , available_stock
                , unit
                , location
                , warehouse)
        select a.article
            , b.art_descr
            , a.article_id
            , a.client
            , a.value_1
            , a.unit_code
            , a.location
            , a.warehouse
        from aststock a
            join
                algarticle b 
            on a.client = b.client 
                and a.article = b.article 
        where a.client = 'cp'

Now what I need to do is continue to run that script but have it update available_stock when there is a duplicate key, and insert new rows when there is not. The key is on (article, location, warehouse)

I believe I need to use the code: ON DUPLICATE KEY UPDATE 'available_stock'

I'm missing something though. The other questions that I can see on this topic involve only adding 1 or 2 lines, so they specify what values to update. I'm confused as to how to make this work. Also, when I start typing ON DUPLICATE at the end of that code, SQL gives me a squiggly line under the ON, indicating that I'm putting it in the wrong place.

philm
  • 1
  • 1
  • 2

1 Answers1

0

Answered my own question. Since I was using TSQL I had to use a merge statement.

philm
  • 1
  • 1
  • 2