Questions tagged [sql-merge]

`SQL MERGE` statement allows us to insert new rows into table and update existing rows depending on given condition. Use this tag in addition to [tag:sql] to make question better categorized.

SQL MERGE statement allows us to insert new rows into table and update existing rows depending on given condition.

Examples of using MERGE statement:

Use this tag in addition to to make question better categorized.

324 questions
0
votes
2 answers

How do I convert these SQL statements into more efficient statements

I have the following code: CURSOR Q1 IS SELECT COL1, COL2, COL3, COL4, COL5, COL6 FROM TABLE1; CURSOR Q2 IS SELECT COL11, COL22, COL33, COL44, COL55, COL66 FROM TABLE2; PRESENT BOOLEAN; FOR X IN Q1 LOOP PRESENT := FALSE; …
xpetta
  • 607
  • 12
  • 28
0
votes
2 answers

Want to update and insert at the same tame, both of them not only one

I have a table where is stored information about countries, and i have to change ISO-code from 3 characters to 2 characters ISO-code. for example i have data like this. and the question is, first i want to update all of them which are consisting…
BOMBERMAN
  • 21
  • 4
0
votes
1 answer

Update the changed row of target table only using source table if there is any value mismatch between 2 columns

Table T1 ID C1 C2 C3 -- -- -- -- 1 x y z 2 p q r 3 a b c Table T2 1 x y z 2 p q1 r 3 a b c1 Need to update all values of T2 into T1 to ensure both table should have same value.This can be achieved by merge…
Munu
  • 103
  • 5
  • 15
0
votes
1 answer

Approaches that would allow to make the MERGE opearation in SQL work faster

Could you recommed approaches that would allow to make the MERGE opearation in SQL to work faster? I believe that the question is all about knowledge and experience and should not be considered as opinion based, since anything which would make the…
hellouworld
  • 525
  • 6
  • 15
0
votes
0 answers

Merging with one of the multiple matching records in Target Table using merge update

I have two Tables with almost identical columns. The requirement is to merge the Rows of source Table into Target table. The Problem is, the Target table has more than one matching rows with differne type of Expenses and I want to merge the Source…
Atul Jain
  • 19
  • 7
0
votes
1 answer

ORACLE SQL : IF EXISTS UPDATE ELSE INSERT

Lets say : i have data on OracleDb like what i mentioned above. TRANSFERNUMBER | VALUE1 | VALUE2 2250 | 1000 | 2000 2251 | 1000 | 3000 My main purpose is when add some data on table if data exists it should…
Bora.Ozgur
  • 65
  • 1
  • 7
0
votes
1 answer

SQL Server MERGE with conditions not merging

I'm trying to do a simple update of my table when the collector has different data than the final table. I'm using the code below. When the first SELECT runs it tells me that the two columns both have data in them. After the MERGE statement runs,…
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
0
votes
1 answer

DELETE and INSERT using MERGE statement in ORACLE

I have entity Employee, and it has a field List accountIds. so table structure looks like this: CREATE TABLE EMPLOYEE ( ID varchar2(255) not null, OBJ_ID varchar2(36), NAME varchar2(255), VER_NBR number(19,0), CREATEID varchar2(255) not…
0
votes
1 answer

Merge Into Statement Erroring out at "Merge"

I get the following error when trying to run a SQL "Merge Into" statement in Postgres: "ERROR: syntax error at or near "MERGE". We are on Postgres 12. Here is the SQL you can use to test.SET AUTOCOMMIT = ON; /* Drop tables when done testing...…
mp75
  • 21
  • 2
0
votes
1 answer

The multi-part identifier could not be bound in merge

I am using below merge and getting "The multi-part identifier "MasterSource.monthvrip" could not be bound" error. Checked a lot in internet but no luck . Looks like using some defined keyword but not able to figure out. Any suggestion will be…
Andrew
  • 183
  • 2
  • 14
0
votes
1 answer

Insert multiple rows using SQL Merge statement when condition matched

Have Table with Non Identity Primary key. so whenever we insert new record we have to pass Primary key also. I have to insert into the above table when record is not matched using Merge statement. But the problem is i could not increment the…
0
votes
2 answers

What’s wrong in this merge operation?

I am performing a MERGE operation in Oracle 11g, but they are returning more rows than the expected. create table sales(product varchar2(20),month date, amount number(10)) insert into sales values('LG','01-Jan-17',20000); insert into sales…
0
votes
2 answers

Improving horrible MERGE performance

I recently asked a question about how to solve a problem in tsql query which led me to use a MERGE statement. This is however proving problematic as its performance is horrible. How do I get inserted row Id, along with related data back after insert…
JensB
  • 6,663
  • 2
  • 55
  • 94
0
votes
1 answer

Tera Data: Missing/Invalid SQL statement'E(3810)

I have this simple merge statement but it failed when running. Any advice is appreciated. MERGE INTO HP.SampleAll as A USING ( select ALIGNED from HP.Sample2 ) as B ON (A.md_nbr = B.md_nbr) WHEN MATCHED THEN UPDATE SET…
TTPitt
  • 11
  • 1
0
votes
3 answers

Problem in merge condition in oracle when merging two tables

I have a table which has data as: id payor_name --------------- 1 AETNA 2 UMR 3 CIGNA 4 METLIFE 4 AETNAU 5 ktm 6 ktm Id and payor_name are two columns.So, My expected output is: id payor_name --------------- 1 AETNA …
Random guy
  • 883
  • 3
  • 11
  • 32