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

single upsert statement

$
0
0

Hi All,

I want to update/insert data in a table based on the value of a primary column

Ex:

Create Table Table1
(
AccountID INT,
LastName Varchar(10),
FirstName Varchar(10),
Email Varchar(50),
Address1 Varchar(10),
Address2 Varchar(10),
City Varchar(20),
State Varchar(20),
Country Varchar(20)
)

Create Table Table2
(
AccountID INT,
LastName Varchar(10),
FirstName Varchar(10),
Email Varchar(50),
Address1 Varchar(10),
Address2 Varchar(10),
City Varchar(20),
State Varchar(20),
Country Varchar(20)
)


Table1 will get new data or updates from another process. Now i need a SQL to update/insert Table2 if the AccountID is existing then i have update all the remaining fields if accountID is not found then i have to insert new record in Table2.

Is there simple way of doing this?

Thanks a  lot for your time.

Eshwar.


Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.


Viewing all articles
Browse latest Browse all 12890

Trending Articles



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