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
1 answer

SQL Server Merge - Output returning null deleted rows as inserted

I'm using MERGE to sync data in a table, and I'm seeing some wrong (to me) behavior from SQL Server. When I OUTPUT the INSERTED.* values, and a row was deleted, the MERGE command returns a row with all NULL columns for each row that was deleted. For…
Sanders
  • 438
  • 3
  • 13
0
votes
2 answers

Updating a column using values from a Lookup table

I have a list of products in table, products. This may contain over 5 million records. prod_code prod_region prod_desc prod_type ------------------------------------------------------ 1001 R2 r2 asdasa 1001 R1 …
Noel
  • 10,152
  • 30
  • 45
  • 67
0
votes
1 answer

Getting the value of a primary key from a merge

I have a stored proc that has a merge .. into statement. I am trying to get the value of the primary key out of the stored proc. SET @NewCompanyID = @CompanyID .... merge company as c using ( select @CompanyID) as compAlt (company_id ) on…
CFNinja
  • 3,571
  • 4
  • 38
  • 59
0
votes
1 answer

Update through merge

I have a design problem while creating a procedure. Suppose I have to update all rows in a table using data in other columns in same row. Say table1 has 3 columns A, B and C and I need to update all rows as C=A+B. So I can use: update table1 set…
kamal
  • 1
0
votes
2 answers

jOOQ MERGE support for PostgreSQL conditional insert

I had understood that jOOQ would simulate SQL MERGE on systems (such as PostgreSQL) that don't support it. I have a table with a serial (autoincrement) "id" column and a string "uri" column. I want to use numeric IDs instead of URIs in my database,…
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
0
votes
0 answers

DB2 jdbc driver not capable of MERGE?

I have written a pretty simple MERGE statement that I can execute successfully in DB2 Control Center but when I try to do it via JDBC, it says the driver is not capable? Is this really the…
fnCzar
  • 3,153
  • 4
  • 26
  • 28
0
votes
1 answer

How to merge insert a column from a temp table and parameters from stored procedure?

is this the "right" way to do that? merge dbo.tableA as tgt using (select #temptable.pkid, @spParam1 as col1, @spParam2 as col2 from #temptable) as src on tgt.pkid = src.pkid when not matched by target when insert (pkid, thing1, thing2) values…
dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
0
votes
1 answer

SQL Merge failing to insert then update two identical rows from the target table

I am trying to merge two tables using SQL Merge, in the below script: BEGIN TRAN; DECLARE @T TABLE(Id BigInt); MERGE Target AS T USING Source AS S ON (T.ObjectName = S.ObjectName) WHEN NOT MATCHED BY TARGET THEN…
Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90
0
votes
1 answer

Oracle SQL Merge Statement Issue

I have a sql that looks more or less something like the below one - declare some_Date date; begin select sysdate into some_Date from dual ; merge into (SELECT cola, colb, colc FROM TableA WHERE status='A' AND some_id = 101) P USING (…
jagamot
  • 5,348
  • 18
  • 59
  • 96
0
votes
3 answers

Merging when using SQL GROUP BY

my data in the mySQL DB looks like this (but not only this 4, i have many persons which are appearing more then once, but with different qualifications and different modified dates Selection would be something like: SELECT * FROM table where…
Joergi
  • 1,527
  • 3
  • 39
  • 82
0
votes
1 answer

SQL Server Bulk Insert/Update: checking if record exists with duplicates in source

I have the following tables which join on idProduct = id (one to one): Products idProduct description ProductKeys id ProductKey I need to create a trigger on the Products table for single and bulk inserts and updates which updates the key in…
Rivka
  • 2,172
  • 10
  • 45
  • 74
0
votes
1 answer

Stored Procedure as Parameter in MERGE [INSERT] Statement

I need to merge two tables in following way: Target has one extra Column ID. This Id is coming FROM another Single Column Master Table. While Inserting the Record in Merge Statement I need to INSERT a new row into mater table and use its id to…
-1
votes
1 answer

"ERROR IN PKG_PAYMENT AT LINE 280 -> ORA-38104: Columns referenced in the ON Clause cannot be updated: \"CANUMBER\""

PROCEDURE INSERTORUPDATE_BILLINGACC( IN_CA_NUMBER IN VARCHAR2, IN_BILL_CUST_ID IN VARCHAR2, OUT_RETURN_STATUS OUT VARCHAR2, OUT_RETURN_CODE OUT NUMBER, OUT_RETURN_MESSAGE …
Xzone
  • 1
  • 1
-1
votes
2 answers

ORA-38104 when trying to update my table using merge

I have a stored procedure in which I want to update some columns, so I wrote below code: PROCEDURE UPDATE_MST_INFO_BKC ( P_SAPID IN NVARCHAR2 ) AS BEGIN MERGE INTO tbl_ipcolo_billing_mst I USING ( SELECT …
Nad
  • 4,605
  • 11
  • 71
  • 160
-1
votes
1 answer

SQL Merge using date range on source

I'm trying to create a query that will merge only Trips occurring in the next 3 days. The Query will be ran on Microsoft flows nightly to populate company app. Db is running on Azure SQL and [Trip Date] data type is datetime2. I have tried between…
rshep
  • 1
  • 1
1 2 3
21
22