A SQL statement that can conditionally insert, update, or delete target rows.

learn more… | top users | synonyms

1
vote
1answer
14 views

Using SQL MERGE to UPDATE a CTE

I have the following SQL... DECLARE @FromDate DATETIME ,@toDate DATETIME IF @toDate IS NULL SET @toDate = GETDATE() IF @FromDate IS NULL SET @FromDate = DATEADD(MONTH, -13, @toDate) SET @...
17
votes
1answer
215 views

Why does this MERGE statement cause the session to be killed?

I have the below MERGE statement which is issued against the database: MERGE "MySchema"."Point" AS t USING ( SELECT "ObjectId", "PointName", z."Id" AS "LocationId", i."Id" AS "Region" ...
2
votes
2answers
48 views

Using Variables to contain column names for SQL Server Merge statemtns

I'm trying to automate the column list grab for a merge job, and running into a bit of a head scratcher. I don't want to have to manually type out all of the column names, and thought I may be able to ...
2
votes
1answer
51 views

SQL Merge Statement Spending Large Amount of Time Sorting on Primary Key

We are looking to use the SQL MERGE statement in SQL Server 2012 to handle data replication for a data warehouse that we have access to from the manufacturer of a 3rd party application we use for data ...
3
votes
1answer
47 views

How to maintain trees and their roots in SQLite

I have a (SQLite) database with a table representing nodes in a forest (set of trees): create table "Node" ( "id" Text primary key, "parent" Text references "Node" ("id") -- parent node ...
0
votes
3answers
25 views

How to insert/combine values from multiple tables?

I have multiple tables (12 for each month) that have 3 columns each ("code", "test_name", "value") Example: January code | test_name | value 0001 name1 17 0002 name2 45 0005 ...
2
votes
1answer
65 views

Update the value when the row already exists

I have table 'A' in schema 'USER'. There are three columns in this table. below are the names of the columns: id (primary key) name age I want to insert a row in this table, but if the row is ...
1
vote
2answers
47 views

How can I merge duplicate rows in a single table?

I have a table with duplicate barcodes (barcode) and carts (cart) and (Quantity_counted_IN) and (Quantity_Counted_out). I want to merge all duplicate records that have the same barcode and cart ...
0
votes
0answers
23 views

Can I merge a newer version of a database with a backup copy

I have a backup of a database, and a newer version of the database. The newer copy, however, is does not include information that is in the older backup. I want to merge these into one - all tables. ...
2
votes
1answer
64 views

Conflict resolution in versioned tables

I'm trying to merge two workspaces that contain version-enabled tables. I can't figure out how to resolve conflicts, because I have a lot of rows with the same ID value. They differ only in time ...
0
votes
0answers
22 views

The process can not access the file because it is being used by other process

I have publisher and distributor on the same machine with 2012 sql server. Created a new subscription and it started downloading the snapshot. After a few snapshot downloads, it throws the following ...
1
vote
2answers
58 views

Getting Only What Changed from SQL Server 2005

We have a 17 store system which are on SQL Server 2005 Standard Edition and on Windows 2003 server. We currently have the following process: At each store we have an SQL job which runs a procedure ...
1
vote
0answers
38 views

Merge databases with sql only: firefox places and visits

I have two tables in each of two dbs: places: id, url (unique), visits: id, place_id, timestamp, type. I need to merge those databases: There are one main database and one "to-merge". The unique ...
2
votes
1answer
282 views

How to merge 2 tables in Oracle

I have 1 big table with 25 milions of rows and i have to merge data of another table with 500,000 rows into the big table. the rows of both tables have the same columns and i have to check if the key ...
1
vote
1answer
600 views

MERGE with IDENTITY_INSERT ON does not work if Identity is not the primary key

I frequently use MERGE statements and am quite familiar with it. Now I ran into a situation where some tables have IDENTITY columns that are not the primary key. In this situation the script failed ...
0
votes
1answer
32 views

SQL Server Merge mandate

Does the target table need to be identical to source table schematically? Specifically: 1) do they need to have the same number of columns and do the column types must be the same?, 2) do the column ...
0
votes
2answers
90 views

UPDATE with Oracle MERGE statement

I have following MERGE statement. Table table_A contains list of ID (cli_id) and column fb_flag. The query inside update the column fb_flag in table_A when cli_id is matching. Which works. However ...
0
votes
1answer
40 views

Merging data from multiple tables

I'm trying to merge data from multiple tables in different databases on the same server however the result is incorrect (i.e. the number of rows returned is more than what it should be). Here's the ...
2
votes
2answers
329 views

MERGE command in SQL Server 2005

I have been trying to develop a MERGE in SQL Server 2005. It does not have all features yet, because I have been struggling in "how to put the merge logic WORKING AS A SET, rather than rows". ...
0
votes
1answer
59 views

SQL Server - Update using Join in Merge

Scenario : I need to update values in a table by joining it with another temp table. But I am using a Merge statement to check various scenarios and update the values in the table when the condition ...
5
votes
4answers
536 views

How can I avoid repeating the same condition in a “when matched then update” clause?

I want to merge one table into another. I need to apply conditional logic in my WHEN MATCHED clause, which would ideally be done like this: MERGE INTO ATable AS a USING BTable AS b ON a.ID = b.ID ...
3
votes
1answer
95 views

Merge causing deadlocks

We are running MS SQL Server 2008 R2. We've got a VendorMaster table (with about 8700 rows) that we are trying to keep in sync across two databases using a Merge statement. The merge code runs every ...
3
votes
0answers
101 views

SQL Server MERGE statement efficiency

We are using the following query to merge new data between tables. -- Merge descriptions from Sync_CheckPointDescriptions table with temporary table #temp MERGE CheckPointDescriptions AS TARGET ...
1
vote
0answers
89 views

Unable to get stable set of rows

I am trying to update latitude/longitude where missing using a merge statement. It errors: ORA-30926: unable to get a stable set of rows in the source tables. I thought that meant that the inner query ...
0
votes
0answers
31 views

SQL Server Merge - returning error messages properly - finding record where error occured

I have a table structure like: Parent - Child 1 - Child 2 - Child 3 In two databases, one of them has some extra fields. I want to get the data(which can be huge) from one database into another ...
0
votes
0answers
14 views

Are tables during a merge function updated dynamically?

If for example, I have a column age in both tables. My merge condition for two tables is when table1.age=table2.age. My WHEN MATCHEDinstruction is to increment table1.age by 1. So if a row with age=5 ...
1
vote
0answers
37 views

Mysteriously Updated Rows

Here's the trigger causing the problem: USE [SalesDb] GO /****** Object: Trigger [dbo].[trgAfterUpdate] Script Date: 7/16/2015 6:34:01 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ...
0
votes
0answers
40 views

Merging data from two slightly different datasets

A bit of backstory: we used to have a single Postgresql db that we had to duplicate when we opened a new office. So at that moment there were two indipendent dbs with perfectly identical data. Over ...
1
vote
0answers
89 views

SQL Server tool for merging rows [closed]

We have a SQL Sever 2008 database that occasionally receives bad data from customers. The issue we are trying to address here is that sometimes duplicate records are created where one row has some of ...
2
votes
0answers
74 views

Merging Databases with Same Schema

I have been developing a (MySQL) database in the cloud for the past few months to link in to a web based service. Following a change to the roadmap the initial clients will be running on standalone ...
2
votes
1answer
2k views

moving a Partition of Partitioned Table to other File Group, SQL Server

I created partitioned table on DateTime column. for last 6 month. I placed 3 oldest month on a file group named 'FG_OlderData', and 3 newest month on a file group named 'FG_NewerData'. Partition ...
1
vote
3answers
446 views

Merge replication throws PRIMARY KEY violation during the initialization of Subscriber

I am using SQL Server 2014 SP1 to set up merge replication on Windows 2008. The databases (Publisher & Subscriber) are restored from the production back up of SQL Server 2005 publisher database. ...
0
votes
0answers
18 views

After merge replication setup, tables at subscriber not getting any data from publisher

I have created a merge replication setup through Replication Wizard. After sync, it is observed that the subscriber DB gets created with the exact tables in publisher as intended, but on the ...
7
votes
1answer
590 views

Merge row size overflow in SQL Server - “Cannot create a row of size..”

The target table to which I'm trying to merge the data has ~660 columns. The code for the merge: MERGE TBL_BM_HSD_SUBJECT_AN_1 AS targetTable USING ( SELECT * FROM ...
3
votes
1answer
95 views

how would i merge a column where matches a different column? [closed]

It's very similar to the below post How to merge column in mysql depending on match table user I would like to Merge customer_id from table user to table cust where customers_firstname AND ...
0
votes
1answer
209 views

SELECT ROWS WITH SIMILAR ID AND MERGE THE FILED VALUES IN ONE

My situation is as follows. I have the query below and the query is doing its job pretty well. However I have excluded one able from it which is field_data_field_luogo and the rows inside this can ...
1
vote
2answers
2k views

Merge faster than Insert

Are there any advantages/disadvantages of making use of a merge over a insert function? Can an insert statement make use of the `OUTPUT' Note: the ON clause for the merge is set to 1=0 (always insert)...
1
vote
1answer
125 views

Shorthand for on primary key?

Is there a shorthand for merging rows based on the primary key? For example: MERGE INTO [MyDatabase].[MySchema].[MyTable] AS target USING [MyLinkedServer].[MyDatabase].[MySchema].[MyTable] AS source ...
0
votes
0answers
56 views

Is this MERGE statement correct?

Question: Is this MERGE statement correct ? emphasis on the ON and AND .. are they rightly placed? MERGE INTO VR_ORDER_LINE USING (SELECT * FROM E14) ON ( VR_LINE.RETAIL_NUMBER = E14_LOAD....
0
votes
1answer
546 views

Insert All Columns from one table into another table MYSQL

I am trying to insert multiple columns with their data from one table into another table, without a common column (i would expect a cross product in the result). I am not sure how that's possible, ...
1
vote
1answer
663 views

How do I update and insert specific set of rows to an existing table using Merge in SQL Server 2008 R2?

I have a table in the database that I need to update based on the records being passed to it. I am given a table-valued-parameter that has the same schema as the existing table (for all intensive ...
0
votes
2answers
9k views

How to insert or update using single query?

I have a table test having columns id which primary key and auto incremented and name. I want to insert a new record if annd only if there are no records.For example input is id=30122 and name =john ...
1
vote
0answers
235 views

Executing shell commands from SSDT Post Deploy scripts to generate SQL

tl;dr: I'm looking for the equivilant of !! sqlcmd -S $(Server) -o foo.sql -d $database -Q "EXEC sp_generate_merge 'table_name'" in a SSDT post deploy script, but !! doesn't seem to be supported. I ...
0
votes
1answer
61 views

Automating SQL Server Merge Replication Processes [closed]

Hi all is there anyway I can automate the entire process of the Merge Replication?
0
votes
0answers
254 views

How to merge exported SQL Data into restored DB updating only changed rows?

We've just moved two databases from Microsoft SQL Server 2008 instance to another using BACKUP DATABASE on the original system and then RESTORE DATABASE on the new one. Everything went fine but then I ...
1
vote
2answers
746 views

Stored procedure - problem with merge - Insert

I am calling a stored procedure from my c# code . The procedure works fine for update, but fails for Insert. Is the following merge-insert procedure code correct? Any help is appreciated. Here is ...
0
votes
1answer
73 views

Merge two rows into one row

So I have a table that looks like this: And here's my query for that table: select b.Barcode,a.ItemCode,b.Color,b.Size,b.Class,d.Locationcode,c.price, SUM(case when e.description = 'Selling ...
0
votes
1answer
46 views

MSSQL 2000 replication, incrementing an integer column on a single row using an update statement

I have 2 web servers, both of which connect to separate mssql 2000 database servers, these two servers use merge replication in order to collate tracking data. Now each web server runs an update ...
3
votes
1answer
1k views

Merge Problems SQL Server

I'm trying to create a procedure that will take the values from a temporary table, and load them into another table. The second table has a composite unique constraint across its three columns (Not ...
0
votes
1answer
101 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 ...