473,406 Members | 2,369 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,406 software developers and data experts.

Insert Into Select - I need each row Selected to be dependent on orecords previously inserted

new
I am building an effective dated file that shows results to date.

In part 1 of the select I
I process a larges set of input and genrate records for each date in the
processing period for which there has been activity

In part II I then want to select the most recent effective dated record (if
any and whether it existed before this run or was generated by an earlier
insert) and sum it with the record for this date

So my question is: when do the insertions happen and when does the selection
happen so that I can "see" the results of an earlier insertion?

I beleive that this is related to the problem I have seen dealt with before:

insert into tableA select * from tableB where not exists in tableA

I know this could be solved by doing a Select distinct on table B (see below
not that it matters) but I believe I saw a solution where there was a commit
immeadiate or some such thing that caused the exist clause to be evaluated
against tableA including records added earlier.



insert into tableA
select Distinct from tableB
where not exists in tableA

or

insert into tableA
select * from ( select Distinct from tableB ) as tableBB
where not exists in tableA
Oct 9 '06 #1
1 2307
new wrote:
I am building an effective dated file that shows results to date.

In part 1 of the select I
I process a larges set of input and genrate records for each date in the
processing period for which there has been activity

In part II I then want to select the most recent effective dated record (if
any and whether it existed before this run or was generated by an earlier
insert) and sum it with the record for this date

So my question is: when do the insertions happen and when does the selection
happen so that I can "see" the results of an earlier insertion?

I beleive that this is related to the problem I have seen dealt with before:

insert into tableA select * from tableB where not exists in tableA

I know this could be solved by doing a Select distinct on table B (see below
not that it matters) but I believe I saw a solution where there was a commit
immeadiate or some such thing that caused the exist clause to be evaluated
against tableA including records added earlier.



insert into tableA
select Distinct from tableB
where not exists in tableA

or

insert into tableA
select * from ( select Distinct from tableB ) as tableBB
where not exists in tableA

By definition th entire select is processed before teh first row is
inserted.
Otherwise side-effect such as the "Halloween effect" can occur
(http://www.mcjones.org/System_R/SQL_...95-System.html
search for "Halloween")

If you want to see previously inserted rows for each insert you will
need to do single row insert.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Oct 9 '06 #2

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

Similar topics

1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
9
by: Bob Bedford | last post by:
I've a form that use a combobox along with other fields. When the user submit the form, many tests are done. If any test fails, then I show the form again with previously entered values. My...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
5
by: Paul Shaw | last post by:
Can anyone explain why an insert might cause multiple logical bufferpool data reads? Here's a situation that has me scratching my head. Table A's data resides in tablespace B Table A's...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
2
by: Mansi | last post by:
I'm trying to automate excel from c#. One of the things I need to do is to copy/paste/insert rows in excel via c# code. I tried to do the following: 1) Select a row in excel (a12 to k12) 2)...
2
by: leedo | last post by:
Hi, I am almost going crazy with this. I have a table that I bulk insert into from another database using VS2005. I need to change the data in the records before committing the values in the...
0
by: magnolia | last post by:
i created a trigger that will record the changes made to a table .everything works fine except the insert query.whenerever i try to insert a record it fires insert and update triger at the same time...
6
by: lenygold via DBMonster.com | last post by:
Hi everybody: What is the best way to I have 10 tables with similar INSERT requiremnts. INSERT INTO ACSB.VAATAFAE WITH AA(AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP) AS ( SELECT AA_TIN,...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.