0
votes
0answers
33 views

Delete and merge duplicate records from joined tables?

I am trying to delete duplicate records from the output of the query below. If they also meet certain conditions i.e., 'different address type', then I would merge the records. From the following ...
0
votes
1answer
16 views

Can't map invalid columns based on column names in a .dtsx-Package

I have the following problem. I currently have to modify a .dtsx-Package which was originally created by a coworker who is not arounf anymore. This package contains some logic but above all it does ...
1
vote
1answer
56 views

Query hint? for deduplicated CTE in Merge

Referring to this link: Optimizing MERGE Statement Performance The following criteria are given for ideal performance: Create an index on the join columns in the source table that is unique and ...
2
votes
2answers
319 views

Way to do MERGE with update source when target not match?

I am trying to write a stored procedure that will take new values from a temp table, merge them into an actual table, giving me the ids of the inserted rows, and the rows that already exist matching ...
0
votes
0answers
311 views

The OLE DB provider “SQLNCLI10” for linked server “(null)” indicates that either the object has no columns or

When I run the following script its run fine merge RDW_RRR_MAIN_ST.dbo.tmps AS dest USING (select * from RDW_RRR_MAIN_ST.dbo.tmprole cross join RDW_RRR_MAIN_ST.dbo.tmpscreen) as src1 on ...
1
vote
0answers
68 views

RETURNING syntax with multiple columns

Again, another question related to the answer of the one there: Insert with OUTPUT correlated to sub query table So I ended up with this query, written for SQL Server: CREATE TABLE tempIDs ( ...
4
votes
1answer
260 views

A clarification of MERGE best practices

I just wanted to ask a clarification about something on the MSDN from the "Optimizing MERGE Statement Performance" page. I am working with a data warehouse that takes in records from many different ...
0
votes
3answers
13k views

SQL Server - Copy data from one database to another - identical tables, new identity values needed

Here's the thing, I have been running identical copies of my website for two different geographical regions. The site now supports multi-currency pricing so I want to merge both sites together. All ...
0
votes
4answers
3k views

How do I delete only related records in a multi-key MERGE in SQL Server?

Suppose you have something like this: Source table (variable): Values ( LeftId INT NOT NULL, RightId INT NOT NULL, CustomValue varchar(100) NULL ) Target table: Mapping ( LeftId INT NOT ...
3
votes
2answers
1k views

Can I optimize this MERGE statement?

I am attempting a single column merge between two tables. The first table (VisitorSession) has 40,000,000 rows. The second (ShoppingCart) has 9,000,000 rows. In my development environment, the query ...
0
votes
0answers
52 views

Transfer tables from multiple servers into one single server [duplicate]

I have to migrate similar tables present in multiple different servers (30+) into our new server using SSIS package. What would be the right approach towards this? I was successfully able to transfer ...
1
vote
1answer
255 views

Merge Statement + Replication difference for SQL Server 2012

We have a SSIS package that will pull from a source database and run a merge statement to put the data into a "Master" database. (Eventually the "Master" database will be the source of truth, but we ...
19
votes
1answer
7k views

MERGE a subset of the target table

I am trying to use a MERGE statement to insert or delete rows from a table, but I only want to act on a subset of those rows. The documentation for MERGE has a pretty strongly worded warning: It ...
4
votes
1answer
883 views

MERGE with OUTPUT doesn't seem to be doing the right thing

I'm adding a foreign key to a table, and removing any rows that violate the FK, copying them into a ModifiedTable_invalid table. As part of the script, I've got the following MERGE command: MERGE ...
2
votes
2answers
1k views

Merge two records in the same table, keeping foreign key relationships intact for both

I have a table, called SITES, that has three columns, lets say it looks like this: ID Name Path 1 Google http://www.google.com/ 2 Microsoft http://www.microsoft.com/ I also have ...
7
votes
3answers
4k views

SQL Server 2008 merge statement deadlocking itself

I have the following procedure (SQL Server 2008r2): create procedure usp_SaveCompanyUserData @companyId bigint, @userId bigint, @dataTable tt_CoUserdata readonly as begin set ...
7
votes
2answers
943 views

Merge replication fails on executing query

My merge replication was working fine this morning. Since an hour or 2 ago, my synchronisation status windows keeps showing this message: Thread id 3108 will wait for 15 second(s) before retrying the ...
5
votes
2answers
447 views

How to use merge hints to isolate complex queries in SQL Server

I can understand that if I join individual queries that are "individually fast" the combination may become slow because the default execution plan may be non-optimal. However when I know the number ...
6
votes
1answer
2k views

What are my locking options for a Merge statement?

I have a stored procedure that performs a MERGE statement. It seems like it locks the whole table by default when performing the merge. I'm calling this stored procedure inside of a transaction ...