473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SQL0803N duplicates and problems inserting

Is there a way to tell DB2 to continue on error and then to insert
tuples that don't exist in a table?

I'd like to modify the following SQL statement to do that. Executing
this statement results in a SQL0803N error.

I'm using DB2 8.1.

Thanks.

insert into emp_group
(emp_id,group_id,active,
created_by,created_date,
modified_by,modified_date)
select ee.emp_id,
(select group_id from group_lookup where short_name='BR(005901) AT'),
'YES',
'BATCH01', current timestamp,
'BATCH01', current timestamp
from employee ee
join emp_group eg on ee.emp_id=eg.emp_id
join group_lookup gp on eg.group_id=gp.group_id
where
ee.office = '005901'
and gp.attribute='LOB'
and gp.group_name='SPSS';

Mar 4 '08 #1
4 6061
On Mar 4, 3:09 pm, "gimme_this_gimme_t...@yahoo.com"
<gimme_this_gimme_t...@yahoo.comwrote:
Is there a way to tell DB2 to continue on error and then to insert
tuples that don't exist in a table?

I'd like to modify the following SQL statement to do that. Executing
this statement results in a SQL0803N error.

I'm using DB2 8.1.

Thanks.

insert into emp_group
(emp_id,group_id,active,
created_by,created_date,
modified_by,modified_date)
select ee.emp_id,
(select group_id from group_lookup where short_name='BR(005901) AT'),
'YES',
'BATCH01', current timestamp,
'BATCH01', current timestamp
from employee ee
join emp_group eg on ee.emp_id=eg.emp_id
join group_lookup gp on eg.group_id=gp.group_id
where
ee.office = '005901'
and gp.attribute='LOB'
and gp.group_name='SPSS';

I think using the MERGE statement might be your best bet. In the WHEN
NOT MATCHED clause you'd do the INSERT, otherwise (i.e., WHEN MATCHED)
no-op.

--Jeff
Mar 4 '08 #2
"jefftyzzer" <je********@sbcglobal.netwrote in message
news:1c**********************************@i12g2000 prf.googlegroups.com...
I think using the MERGE statement might be your best bet. In the WHEN
NOT MATCHED clause you'd do the INSERT, otherwise (i.e., WHEN MATCHED)
no-op.

--Jeff
Obviously, the PK and/or unique index would have to be removed.
Mar 5 '08 #3
Thanks Jeff,

Merge works like a charm.

merge into emp_group
using (
select ee.emp_id,
(select group_id from group_lookup where short_name='$g_short')
group_id,
'YES' active,
'BATCH01' created_by, current timestamp created_date
from employee ee
join emp_group eg on ee.emp_id=eg.emp_id
join group_lookup gp on eg.group_id=gp.group_id
where
ee.office = '005901'
and ee.flag='NO'
and gp.attribute='LOB'
and gp.group_name='SPSS' ) as a
on a.group_id=emp_group.group_id
and a.emp_id=emp_group.emp_id
when not matched then
insert
(emp_id,group_id,active,
created_by,created_date)
values (a.emp_id,a.group_id,a.active,a.created_by,a.creat ed_date)
else ignore;
Mar 13 '08 #4
gi*******************@yahoo.com wrote:
Thanks Jeff,

Merge works like a charm.

merge into emp_group
using (
select ee.emp_id,
(select group_id from group_lookup where short_name='$g_short')
group_id,
'YES' active,
'BATCH01' created_by, current timestamp created_date
from employee ee
join emp_group eg on ee.emp_id=eg.emp_id
Without diving into the details in this query, the fact that you refer
to the
MERGE target here strikes me as very odd.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 14 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: christof hoeke | last post by:
hello, this must have come up before, so i am already sorry for asking but a quick googling did not give me any answer. i have a list from which i want a simpler list without the duplicates an...
9
by: paul | last post by:
Hiya everyone, I have two tables in SQL 2000. I would like to append the contents of TableA to TableB. Table A has around 1.1 Million Records. Table B has around 1 Million Reocords. ...
3
by: bellefy | last post by:
Hi All, I have a fairly large table with approx 30K rows that updates every night via a cron script that automatically downloads the 2 new csv's. The problem is the files are downloaded from...
4
by: Drew | last post by:
I have a permission tracking app that I am working on, and I have made the insert page for it. I am having issues on how to prevent duplicates from getting entered. Currently the interface for...
9
by: Curtis Stanford | last post by:
I'm in a situation where I need to load an ASCII file into a database. No sweat so far right? The records are indexed by date and I have a unique index on date. The ASCII can overlap, meaning it...
1
by: Maya | last post by:
Hello, In the array abc: abc = "john" abc = "jack" abc = "john" abc = "peter" Is there an easy way to check for "john" existence before inserting
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
1
bugboy
by: bugboy | last post by:
Ok so this has got me stumped. I need to insert 400,000 words into a (unique) column and i have two problems: 1. My source data is not clean, there are around 1% repeated words.. i'm pretty sure...
11
by: richardkreidl | last post by:
I'm trying to check for duplicates before I do an INSERT into the Access database table. I basically want to alert the user if the 'ProjectName' and the 'MileStones' are already in the table.. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.