Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Help with Except clause

$
0
0

I have a source database dbtest02 with a table called article with the following data

id           type       cost

001         1              40       

002         2              34       

003         7              120      

004         4              160

                        

My target table article is in database dbtest01 and has the following data

 id          type       cost       action

001         1              40          new

002         2              80          new

003         3             120        new

Using the Except clause, I can identify the differences between the tables

SELECT id,type, cost

FROM dbtest02.article

EXCEPT

SELECT id,type, cost

FROM dbtest01.article

id           type       cost

002         2              34       

003         7              120      

004         4              160

These rows will be added to the target table, however, I need to mark the action column if the row is updated or new. My Except clause query needs to output the following

id           type       cost       action

002         2              34          update

003         7              120      update

004         4              160        new

Could you please help me with this output?

Many thanks


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>