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
-1
votes
2 answers

Python Script for SQL Server - Update values with MERGE

I have this python function which inserts to a SQL database. The script is such that every time it is rerun it will have to insert the same row over again in addition to new rows. Eventually I will be changing this so that it only inserts new rows…
Jonny1998
  • 107
  • 1
  • 1
  • 13
-1
votes
3 answers

Insert or update if already exists

merge into bonuses using( select * from bonuses)s ON s.employee_id = '111' WHEN MATCHED THEN update set bonus='555' WHEN NOT MATCHED THEN insert insert into BONUSES (employee_id) values(115) Table`s insert queries are insert into BONUSES…
Mano
  • 19
  • 1
  • 1
  • 6
-1
votes
1 answer

Merge Query in SQL Server with conditional update

I have a table with duplicate records. The table format is like this FIRST Day input Table Name-ABC ani cdate 7076419812 2016-10-12 00:00:00.000 9168919394 2016-10-12 00:00:00.000 6282358407 2016-10-12 00:00:00.000 9168834643 2016-10-12…
Ramdeo angh
  • 179
  • 9
-1
votes
2 answers

Using MERGE in SQL

I have two tables- T1, T2 with identical table structure. I want to insert new rows in T2 from T1 if they don't already exist in T2, and also update the existing data in T2 on the primary key may be. Can someone help me with the SQL for this please…
Newbie
  • 713
  • 2
  • 10
  • 19
-1
votes
1 answer

SQL Error: ORA-00905: missing keyword, can someone please tel me whats wrong with the below merge statement

MERGE INTO table_a PARTITION (x) A USING (SELECT distinct col1,col2 FROM table_b)b ON (A.col1=B.col1(+) AND A.col2=B.col2(+)) WHEN MATCHED THEN UPDATE SET col3='Y' WHEN NOT MATCHED THEN UPDATE SET col3='N';
-3
votes
1 answer

TSQL Merge Slow After First Success Index Issue?

Using MSSQL 2022. Source temp table has 156,289 rows. Destination table has zero rows. Use case is to insert rows from temp->destination where rows do not already exist in destination. 4 columns determine if a row is unique. Using Merge When Not…
Snowy
  • 5,942
  • 19
  • 65
  • 119
-3
votes
1 answer

Updating SCD2 with MERGE statement

I want to update the SCD-2 table using MERGE statement. So I have: MERGE TARGET as t USING SOURCE as s ON s.KEY = t.KEY Case 1: WHEN MATCHED and s.CHECKSUM <> t.CHECKSUM In this case I want first UPDATE row in TARGET set row_actual_to =…
Grigory P
  • 191
  • 1
  • 8
  • 24
-3
votes
1 answer

How to update a column using another column's multiple data?

test1 t1 t2 1 test2 x 1 2 3 upto 20 so I want all the x values copy into t2. How should I? More detailed : There r 2 tables 'test1' , 'test2'. ' test1 ' having 2 columns i.e ' t1 ' , ' t2 ' and ' test2 ' having 1 column i.e ' x '. so I…
Ranjan
  • 1
  • 3
-4
votes
1 answer

MERGE update with duplicates

I am trying to UPDATE target table but in source table I have duplicate data. I am trying in Azure SQL Server database. All will be ok with HASHBYTES but if I remove HASHBYTES it will raise an error: drop table if exists #source drop table if exists…
1 2 3
21
22