473,785 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on a UPDATE query

Hello again. I previously inquired about updating 1000 records at a
time in a script (not using cursors). Now I have to take it one step
further. I want to update records from two different records at once.
I have half of the step done but cant seem to fit the seconds part in
anywhere:

db2 "update (select * from EMPLOY where NAME IN (select NAME from
ACCOUNT where IDSTATUS <-1 fetch first 1000 rows only)) set
WORKIN='N', data_TITLED='N' , COMMIS=100"

This works fine in the loop for the first 1000 records it finds in the
ACCOUNTs table. The update of the columns in the EMPLOY table work.
But...I want to set the IDSTATUS column in the ACCOUNT table to -1 at
the same time.

Any advise on an easy way to do this?

By the way, I tried two separate queries...this one and one to do the
update on the ACCOUNT table but it seems the second update does not
always give me the same results as the first update...so this gets me
in trouble.

Last, is there any good resources for complex db2 queries?

DB2 UDB 8.2 / AIX 5.4

Aug 12 '06 #1
2 12544
shorti wrote:
Hello again. I previously inquired about updating 1000 records at a
time in a script (not using cursors). Now I have to take it one step
further. I want to update records from two different records at once.
I have half of the step done but cant seem to fit the seconds part in
anywhere:

db2 "update (select * from EMPLOY where NAME IN (select NAME from
ACCOUNT where IDSTATUS <-1 fetch first 1000 rows only)) set
WORKIN='N', data_TITLED='N' , COMMIS=100"

This works fine in the loop for the first 1000 records it finds in the
ACCOUNTs table. The update of the columns in the EMPLOY table work.
But...I want to set the IDSTATUS column in the ACCOUNT table to -1 at
the same time.

Any advise on an easy way to do this?

By the way, I tried two separate queries...this one and one to do the
update on the ACCOUNT table but it seems the second update does not
always give me the same results as the first update...so this gets me
in trouble.

Last, is there any good resources for complex db2 queries?

DB2 UDB 8.2 / AIX 5.4
Something like this should do (not tested)
WITH updaccount(name )
AS (SELECT name FROM OLD TABLE(UPDATE (SELECT name, data_titled
FROM ACCOUNT
WHERE IDSTATUS <-1
FETCH FIRST 1000 ROWS ONLY)
AS U
SET IDSTATUS = -1))),
updemploy(dummy )
AS (SELECT 1 FROM OLD TABLE(UPDATE EMPLOY
SET WORKIN='N', data-titleid='N'
COMMIS=100
WHERE name IN (SELECT name
FROM updaccount)))
SELECT dummy FROM updemploy

I can teach you in person in Anaheim. Simply attend "SQL on Fire!"

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

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 12 '06 #2
Serge Rielau schrieb:
shorti wrote:
Hello again. I previously inquired about updating 1000 records at a
time in a script (not using cursors). Now I have to take it one step
further. I want to update records from two different records at once.
I have half of the step done but cant seem to fit the seconds part in
anywhere:

db2 "update (select * from EMPLOY where NAME IN (select NAME from
ACCOUNT where IDSTATUS <-1 fetch first 1000 rows only)) set
WORKIN='N', data_TITLED='N' , COMMIS=100"

This works fine in the loop for the first 1000 records it finds in the
ACCOUNTs table. The update of the columns in the EMPLOY table work.
But...I want to set the IDSTATUS column in the ACCOUNT table to -1 at
the same time.

Any advise on an easy way to do this?

By the way, I tried two separate queries...this one and one to do the
update on the ACCOUNT table but it seems the second update does not
always give me the same results as the first update...so this gets me
in trouble.

Last, is there any good resources for complex db2 queries?

DB2 UDB 8.2 / AIX 5.4
Something like this should do (not tested)
WITH updaccount(name )
AS (SELECT name FROM OLD TABLE(UPDATE (SELECT name, data_titled
FROM ACCOUNT
WHERE IDSTATUS <-1
FETCH FIRST 1000 ROWS ONLY)
AS U
SET IDSTATUS = -1))),
updemploy(dummy )
AS (SELECT 1 FROM OLD TABLE(UPDATE EMPLOY
SET WORKIN='N', data-titleid='N'
COMMIS=100
WHERE name IN (SELECT name
FROM updaccount)))
SELECT dummy FROM updemploy

I can teach you in person in Anaheim. Simply attend "SQL on Fire!"

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

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
For the last part, the best resource outside this newsgroup and
Developerworks articles is the DB2 Cookbook
http://mysite.verizon.net/Graeme_Birchall/id1.html

Aug 12 '06 #3

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

Similar topics

0
2072
by: Somerset Bob | last post by:
I've posted my query at the phpbb forum, where I got half an answer and then no more. I posted it again at another phpbb forum, where I got half an answer and no more. I posted it in alt.php, where I got half an answer, then no more. In desperation, I'm now posting again in alt.php, alt.comp.lang.php and comp.lang.php in the hope that someone will find the time to help. This was my original query:
0
1893
by: Somerset Bob | last post by:
I've posted my query at the phpbb forum, where I got half an answer and then no more. I posted it again at another phpbb forum, where I got half an answer and no more. I posted it in alt.php, where I got half an answer, then no more. In desperation, I'm now posting again in alt.php, alt.comp.lang.php and comp.lang.php in the hope that someone will find the time to help. This was my original query:
4
10238
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline View Query: Select Sq from ( Select substr(to_date(End_Date,"DD-MON-YYYY"),4), End_Date, Rank() Over (Partition by substr(to_date(End_Date,"DD-MON-YYYY"),4) Order by End_Date) As Sq
6
2148
by: John Baker | last post by:
Hi: As those who have looked at this newsgroup recently will realize, I am a neophyte with Access, although I have experienced with Approach (the Lotus product). There are things I could easily do in Approach that appear to require some subtle and complex manipulation in Access. Herein lies my present problem. I have a number of tables, including one called "tblPO", which contains purchase orders. Some of the details of these change...
9
2414
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a single string separated by a user defined character. There is no error trapping (by design), USE AT YOUR OWN RISK.
10
3281
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This wouldn't work (nothing changed): UPDATE tblManuals SET tblManuals.PARTNUM = Trim(); Would someone please tell me how to do an update query that will trim the spaces?
4
2283
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5 companies on a form. 3 of the companies have common employees. I have a table that looks like this:
3
3451
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
6
6438
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the Autoexec Macro looks like the way to go. Could someone please assist? Thank you very much! Mike
16
3520
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 renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10100
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.