A SQL statement that can perform INSERT, UPDATE and DELETE operations in a single statement.
Questions tagged [merge-statement]
52 questions
1
vote
1 answer
T-SQL MERGE statement is not inserting a new record - what is wrong with my code?
The code below is successfully updating an existing record but does not insert the new record where the details do not match and I don't understand why not as the code compiles and does not throw any error messages. I'm sure I have missed something…

Aaron Reese
- 131
- 11
1
vote
0 answers
Real time table alternative vs swapping table
I use SSMS 2016. I have a view that has a few millions of records. The view is not indexed and should not be as it's being updated (insert, delete, update) every 5 minutes by a job on the server to then display update data sets in to the client…

Data Engineer
- 795
- 16
- 41
1
vote
1 answer
SSIS Merge Statment Datetime not updated
I am using Merge Statement in my SSIS package. The problem is that it doesn't update the datetime column when i run the package. It inserts the datetime correctly but doesn't update them from NULL to some datetime if a new datetime is available in…

Mehak
- 13
- 3
1
vote
1 answer
My Merge statement is failing
I have a merge statement which is to insert values into a database. I hit an exception point with an exception error
A MERGE statement must be terminated by a semi-colon (;).
Here is my statement. Could anyone point out what am I missing…

Yuvi
- 528
- 8
- 18
1
vote
1 answer
Strange MERGE behaviour when using static/constant ON clause
CREATE TABLE test (c1 NUMBER(10) NOT NULL);
exec DBMS_ERRLOG.CREATE_ERROR_LOG ( 'test', 'err_test');
I want to insert into table test some values from an other table, and log the errors. I also want to log the ids of records which could not be…

Davor Josipovic
- 5,296
- 1
- 39
- 57
1
vote
2 answers
How can I specify Batch commit in Oracle Merge Statement?
I am doing a bulk insert/update for millions of records using the MERGE statement in oracle. Well, the other options could be to use FORALL making use of BULKCOLLECT and then commit but this operation will be again a slowdown the performance since I…

spaceman
- 11
- 1
- 2
1
vote
1 answer
Performance issue in merge statement
I have a merge statement like below
MERGE DESTINATION AS DST
USING ( SELECT FROM TABLEA WITH(NOLOCK) INNER JOIN TableB .....
) AS SRC
ON(
)
WHEN MATCHED THEN
UPDATE SET column1 =…

Zerotoinfinity
- 6,290
- 32
- 130
- 206
1
vote
1 answer
Merge statement generate exception, but why
This merge statement raise ORA-00905:missing keyword exception. What can be the problem? Something with the WHEN MATCHED branch?
MERGE INTO WORKERPROJECT TARGET
USING (SELECT distinct
w.worker_id,
w.worker_type,
…

czupe
- 4,740
- 7
- 34
- 52
0
votes
0 answers
How to create a data-traced table using merge statement in Bigquery
I want to weekly track the status of each user's record and whether they changed their status. Currently, there's a table to weekly update the records of each status. Example as below.
Weekly update Table (First Week)…

Jammy Wang
- 11
- 2
0
votes
0 answers
Oracle OJDBC MERGE Statement and Generated Keys
Does Oracle ~>12 support generated keys using a Merge statement? Some sudo code..
MERGE INTO TARGET_TABLE TRG
USING (SELECT CAST(? AS NUMBER) AS ID FROM DUAL) SRC
ON (TRG.ID = SRC.ID)
WHEN MATCHED THEN UPDATE SET....
WHEN NOT MATCHED THEN
…

cbm64
- 1,059
- 2
- 12
- 24
0
votes
0 answers
SQL Server - Using MERGE statement between 2 Databases on 2 different servers
I'm facing a challenge and I was hoping to get some advices from this community.
I have 2 SQL Server databases on 2 different servers. One with a LOT of data and one that will be used for reporting. The DB used for reporting does not need every…
0
votes
1 answer
SQL Server Merge Update With Partial Sources
I have a target table for which partial data arrives at different times from 2 departments. The keys they use are the same, but the fields they provide are different. Most of the rows they provide have common keys, but there are some rows that are…

Pizza Spaghetti
- 1
- 2
0
votes
1 answer
How do I update the two different tables using if and else condition in Oracle SQL server?
Here is the Query which I need to convert into the Procedure.
MERGE INTO table1 SAI
USING
:SITE_PROJECTS_ID: != null &&:SITE_PROJECTS_ID: != 0 (SELECT * from table2)AX
ON (SAI.SITE_INFO_ID=AX.SITE_INFO_ID)
WHEN MATCHED THEN UPDATE…

anaz_Zean07
- 33
- 7
0
votes
0 answers
I'm trying to create a dynamic merge query inside a stored procedure where target is a history table and source is a temporary table - SQL Server
SET @COLUMNNAMES_HIST= ( SELECT STRING_AGG( COLUMN_NAME, ' ,') COLUMN_NAMES FROM INFORMATION_SCHEMA.COLUMNS WHERE UPPER(TABLE_SCHEMA) = '@SCHEMANAME' AND UPPER(TABLE_NAME) = '@TABLE_HIST';
SET @MERGESQL = 'MERGE ' + @TABLE_HIST + '…

sga
- 1
- 2
0
votes
2 answers
How can I use insert with select from other table in a merge statement?
I have this query.
MERGE sales.category t
USING sales.category_staging s
ON (s.category_id = t.category_id)
WHEN MATCHED
THEN UPDATE SET
t.category_name = s.category_name,
t.amount = s.amount
WHEN NOT MATCHED BY TARGET
…
user14743092