Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8170719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:13:09+00:00 2026-06-06T21:13:09+00:00

I need to merge data from one table to another. The data is delivered

  • 0

I need to merge data from one table to another.

The data is delivered via flat files. That is why I use a load table first before moving it into production.

I add a field loadtabletime to the loadtables, so I can tell db2 only to merge one file at a time, even if more than one file is inserted in the load table at one time.

The load table is loaddlp.reservation_insert, and the production table is dlp.reservation.

This is my query:

MERGE INTO DLP.RESERVATION AS E 
USING LOADDLP.RESERVATION_INSERT as et 
   on e.TICKET_SERVER = et.TICKET_SERVER 
  and e.RES_ID = et.RES_ID 
  and et.LOADTABLETIME = '2012-06-09 10:44:17.42236' 
 WHEN MATCHED THEN UPDATE SET (foo) = (bar) 
 WHEN NOT MATCHED THEN INSERT (xyz) VALUES (;akdjf)

the primary key for load table is ticket_server, res_id and loadtabletime; for prod table it’s ticket_server and res_id.

This query fails with the following error:

Could not Update data from the stage to production table RESERVATION.
[[23505] [IBM][CLI Driver][DB2/LINUXX8664] SQL0803N One or more
values in the INSERT statement, UPDATE statement, or foreign key
update caused by a DELETE statement are not valid because the primary
key, unique constraint or unique index identified by “1” constrains
table “DLP.RESERVATION” from having duplicate values for the index
key. SQLSTATE=23505

But, when I remove loadtabletime from the where clause it magically works. Of course, this is not an option as when multiple files are loaded into the load table, you could have pk violations on insert.

When I run:

SELECT count(*) 
  from loaddlp.reservation_insert 
 where LOADTABLETIME = '2012-06-09 10:44:17.42236';

I get the correct results.

Does anyone has an idea of what’s wrong with the query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:13:12+00:00Added an answer on June 6, 2026 at 9:13 pm

    ok, I solved it.

    The key was too add a select query in the ‘using’ field.

    Example:

        MERGE INTO DLP.RESERVATION AS e
    USING (select * from LOADDLP.RESERVATION_INSERT WHERE LOADTABLETIME = '2012-06-09 10:44:17.42236') as et 
       on e.TICKET_SERVER = et.TICKET_SERVER 
      and e.RES_ID = et.RES_ID  
     WHEN MATCHED THEN UPDATE SET (foo) = (bar) 
     WHEN NOT MATCHED THEN INSERT (xyz) VALUES (;akdjf)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Goal: Is to move data from one table to another if the row
I have two datasets each with one data table pulled from different sources and
I need to merge data from 2 tables into a third (all having the
I need to constantly merge (upsert/delete) data from an ODBC data source to a
I need to merge any missing rows in a production mysql database from a
I need to merge two bitmaps to use the resulting bitmap as a mask.
I need to write a java application which can merge docx files. Any suggestions?
I have a table with three fields, one an identity field, and I need
I've got three DataTables that I need to join together, and use the joined
I have some C#/Linq code used to merge data from excel file into db,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.