Search
 
SCRIPT & CODE EXAMPLE
 

SQL

merge query using linked server

--cannot use MERGE with Linked Server, so DELETE then INSERT
--example:
;WITH Source AS 
(
	Select col1, col2, col3
    FROM MySourceTable
)
--delete any matching rows from target
DELETE T
FROM LinkedServerName.DBName.dbo.MyTargetTable T
JOIN Source S ON
	S.col1 = T.col1  --join criteria

--now insert source rows
;WITH Source AS 
(
	Select col1, col2, col3
    FROM MySourceTable
)
INSERT INTO LinkedServerName.DBName.dbo.MyTargetTable
	(col1, col2, col3)
SELECT S.col1, s.col2, s.col3
FROM Source S
Comment

PREVIOUS NEXT
Code Example
Sql :: hierachichal sql query 
Sql :: odoo there is no primary key for referenced table "res_users" 
Sql :: how to create an SQL save method in ruby 
Sql :: Alter precision 
Sql :: debian 10 install postgresql 2ndquadrant 
Sql :: mysql pv progres 
Sql :: Uncomment listen_address=localhost 
Sql :: sqlite table headers 
Sql :: database create table date of birth data type 
Sql :: mysql equivalent decode oracle 
Sql :: Join base on multiple or conditions 
Sql :: group_concat only returns one row 
Sql :: how to change null display in psql 
Sql :: mysql select where field is a value 
Sql :: How to do a cumulative count using Raw SQl / Laravel - Eloquent ORM 
Sql :: oracle date summer time 
Sql :: mysql get nested records 
Sql :: rails sql query converstion 
Sql :: check mysql password with docker container magento 2 
Sql :: conditional index in postgres 
Sql :: oracle query archive mode 
Sql :: create table with error 
Sql :: calcul age 
Sql :: sql comparison operators 
Sql :: connect google bigquery connect using sqirrel 
Sql :: SQL ORDER BY With Multiple Columns 
Sql :: Enable outgoing remote MySQL access 
Sql :: mamp find mysql port number mac 
Sql :: Update Multiple Values in a Row 
Sql :: sql select column name like from multiple tables 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =