We have a table, called COLL. We have another table, named TEST. In
simple terms,
we need to copy values from a column from COLL to a matching record in
TEST. Some
constraints: this must happen in a single SQL statement (in other
words, not embedded in
an app or script) and must work in DB2 v7 on zOS. What we need to do
would be somewhat
simple in V9 or above using SELECT FROM UPDATE, but we're hitting a
wall with V7.
Details:
COLL has these fields:
FK_TEST_ID
FK_PHONE_ID
TEST has these fields:
TEST_ID
FK_PHONE_ID
What we need to do is to copy the FK_PHONE_ID from all records in COLL
into their matching
records in TEST. By 'matching' I mean where TEST's TEST_ID = COLL's
FK_TEST_ID.
In pseudocode (or I should say, pseudo-SQL):
update TEST set FK_PHONE_ID to FK_PHONE_ID from COLL where
COLL:FK_TEST_ID
= TEST.TEST_ID --- do for all rows 3 14869 st*******@gmail.com wrote:
We have a table, called COLL. We have another table, named TEST. In
simple terms,
we need to copy values from a column from COLL to a matching record in
TEST. Some
constraints: this must happen in a single SQL statement (in other
words, not embedded in
an app or script) and must work in DB2 v7 on zOS. What we need to do
would be somewhat
simple in V9 or above using SELECT FROM UPDATE, but we're hitting a
wall with V7.
Details:
COLL has these fields:
FK_TEST_ID
FK_PHONE_ID
TEST has these fields:
TEST_ID
FK_PHONE_ID
UPDATE TEST
SET FK_PHONE_ID = (SELECT FK_PHONE_ID FROM COLL
WHERE FK_TEST_ID = TEST_ID)
WHERE EXISTS(SELECT 1 FROM COLL WHERE FK_TEST_ID = TEST_ID)
I'm unclear how SELECT FROM UPDATE helps here...
MERGE is generally considered the better match:
MERGE INTO TEST USING COLL
ON FK_TEST_ID = TEST_ID
WHEN MATCHED THEN UPDATE SET FK_PHONE_ID = COLL.FK_PHONE_ID
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Hi!
The Merge statement is what you are missing, but is not available until in
V9, alas.
You can try the following
Update TEST A
Set A.FK_PHONE_ID = (Select FK_PHONE_ID from COLL )
where exists (
Select 1 from COLL B
where B.FK_TEST_ID = A. TEST_ID
);
/dg
<st*******@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
We have a table, called COLL. We have another table, named TEST. In
simple terms,
we need to copy values from a column from COLL to a matching record in
TEST. Some
constraints: this must happen in a single SQL statement (in other
words, not embedded in
an app or script) and must work in DB2 v7 on zOS. What we need to do
would be somewhat
simple in V9 or above using SELECT FROM UPDATE, but we're hitting a
wall with V7.
Details:
COLL has these fields:
FK_TEST_ID
FK_PHONE_ID
TEST has these fields:
TEST_ID
FK_PHONE_ID
What we need to do is to copy the FK_PHONE_ID from all records in COLL
into their matching
records in TEST. By 'matching' I mean where TEST's TEST_ID = COLL's
FK_TEST_ID.
In pseudocode (or I should say, pseudo-SQL):
update TEST set FK_PHONE_ID to FK_PHONE_ID from COLL where
COLL:FK_TEST_ID
= TEST.TEST_ID --- do for all rows
On Sep 25, 9:18 pm, "Dan van Ginhoven" <danfa...@hotmail.comwrote:
Hi!
The Merge statement is what you are missing, but is not available until in
V9, alas.
You can try the following
Update TEST A
Set A.FK_PHONE_ID = (Select FK_PHONE_ID from COLL )
where exists (
Select 1 from COLL B
where B.FK_TEST_ID = A. TEST_ID
);
/dg
<steveg...@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
We have a table, called COLL. We have another table, named TEST. In
simple terms,
we need to copy values from a column from COLL to a matching record in
TEST. Some
constraints: this must happen in a single SQL statement (in other
words, not embedded in
an app or script) and must work in DB2 v7 on zOS. What we need to do
would be somewhat
simple in V9 or above using SELECT FROM UPDATE, but we're hitting a
wall with V7.
Details:
COLL has these fields:
FK_TEST_ID
FK_PHONE_ID
TEST has these fields:
TEST_ID
FK_PHONE_ID
What we need to do is to copy the FK_PHONE_ID from all records in COLL
into their matching
records in TEST. By 'matching' I mean where TEST's TEST_ID = COLL's
FK_TEST_ID.
In pseudocode (or I should say, pseudo-SQL):
update TEST set FK_PHONE_ID to FK_PHONE_ID from COLL where
COLL:FK_TEST_ID
= TEST.TEST_ID --- do for all rows- Hide quoted text -
- Show quoted text -
merge is available in db2 8.2 luw This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bryan Guilliams |
last post by:
I'm trying to come up with an elegant, simple way to compare two
consecutive values from the same table.
For instance:
SELECT TOP 2 datavalues FROM myTable ORDER BY timestamp DESC
That...
|
by: William Cleveland |
last post by:
I'm working on a system right now where I have a database (two,
actually, but one is discarded halfway through), but it's created
and used as part of a process (reporting), rather than as the...
|
by: dawatson833 |
last post by:
I have several stored procedures with parameters that are defined with
user defined data types. The time it takes to run the procedures can
take 10 - 50 seconds depending on the procedure.
If I...
|
by: Lyn |
last post by:
I am trying to copy selected fields from one table to another, by reading
the source table record into a recordset (ADO) and then copying the relevant
fields to an SQL statement "INSERT INTO...". ...
|
by: Abhishek Srivastava |
last post by:
Hello All,
Suppose if I have a SQL query like
select p.ID, p.NAME, p.UNIT_PRICE, o.QUANTITY from PRODUCT p ORDERS o
where p.ID = X AND P.ID = O.ID
Here one product can have many orders....
|
by: TC |
last post by:
I need an automated procedure to copy data from an Access table to a
SQL Server table. Speed is important. What is the recommended
technique?
I can export the data from Access, copy it via FTP,...
|
by: Bob |
last post by:
I'm running sql server ver 7.0 SP4.
I have an access project (.adp) that runs a view which is nothing more
than a select statement. Access locks up solid when I try to run this
query - with NO...
|
by: Kelii |
last post by:
I've been trying to get this piece to work for a few hours, but have
given up. I hope someone out there can help, I think the issue is
relatively straightforward, but being a novice, I'm stumped....
|
by: ray well |
last post by:
i need to copy in code a table from a legacy dbase III file into an access
mdb file.
both source and destination tables have the same table names, field names,
field types, & field sizes.
the...
|
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
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |