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

Home Posts Topics Members FAQ

UPDATE problem

Hallo all,

I'm quite new to SQL and I have a problem updating some fields in a table,
maybe some of you in this forum can help me!

This SELECT statement returns the records that I need to update:

select * from A, B
where A.a = 'D' and A.b = 'D '
and A.c = B.c and A.d = B.d
and B.a = '*' and B.b = '*'

The key for the two files is in fields .c and .d but I need to check also
BOTH fields B.a and B.b
because they are my selection flags... and they're not present in file A.

Now I would like to convert this SELECT in an UPDATE as I need to update
two of the fields in file A but this statement doesn't work ... ... !

UPDATE A, B
set A.a = 'X', A.b = 'X'
where A.a = 'D' and A.b = 'D '
and A.c = B.c and A.d = B.d
and B.a = '*' and B.b = '*'

It seems that UPDATE can manage only one table... Which is the solution?
If there isn't a solution with SQL I'll have to write a program to do it!

Best regards to all, Andrea
Nov 12 '05 #1
3 1705
Andrea,

UPDATE A
SET A.a = 'X', A.b = 'X'
WHERE A.a = 'D' and A.b = 'D '
AND (A.c, A.d) IN (SELECT B.c, B.d
FROM B WHERE B.a = '*' and B.b = '*');

There are also solutions using EXISTS.
The newest SQL Standard (and DB2 UDB for LUW) supports a MERGE statement
which you can sue for more complex scenarios.

Cheers
Serge
Nov 12 '05 #2
Hallo Serge,

first really thanks for your help, I've been able to understand
what to do even if I had to modify it.

My AS/400 v5r1 doesn't like the AND (A.c, A.d) IN .... line !

So, just for your information, I changed it like this (after MANY try):

update ORCLR01L A
SET A.ocmagr = 'T', A.ocfilr = 'T ', A.ocnumr = A.ocnumr + 42000
WHERE A.occlir = '008137' and A.ocansr = 2004
AND A.ocmagr IN (SELECT ocmagt FROM ORCLT01L B
WHERE B.ocstat = ' ' and B.ocrept = ' ' and B.occlit = '008137')
AND A.ocfilr IN (SELECT ocfilt FROM ORCLT01L B
WHERE B.ocstat = ' ' and B.ocrept = ' ' and B.occlit = '008137')
AND A.ocnumr IN (SELECT ocnumt FROM ORCLT01L B
WHERE B.ocstat = ' ' and B.ocrept = ' ' and B.occlit = '008137')

I think it's a bit redundant but... it worked.
From the manuals I could't figure out how to write the
AND (A.c, A.d) statement as there was always an error for the
comma or anything else after the first field...

Thank you very much and Ciao, Andrea

"Serge Rielau" <sr*****@ca.e ye-bee-em.com> ha scritto nel messaggio
news:sP******** *******@news04. bloor.is.net.ca ble.rogers.com. ..
Andrea,

UPDATE A
SET A.a = 'X', A.b = 'X'
WHERE A.a = 'D' and A.b = 'D '
AND (A.c, A.d) IN (SELECT B.c, B.d
FROM B WHERE B.a = '*' and B.b = '*');

There are also solutions using EXISTS.
The newest SQL Standard (and DB2 UDB for LUW) supports a MERGE statement
which you can sue for more complex scenarios.

Cheers
Serge

Nov 12 '05 #3
Try EXISTS then. Seems like your version doesn't understand the "row"
wise IN yet.

Cheers
Serge
Nov 12 '05 #4

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

Similar topics

6
7642
by: al | last post by:
Greetings, In the customers table in Northwind db, one can update PK (customerid) and all other fields in the same table. My question is how can you do this in the udpate stat. That is, if one wants to write update query to update all fields including PK, how it can be set? Using PK in the SET statement, gives an error, because this field might have changed during the update? MTIA,
1
6172
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need to be compiled after the trigger has been fired. There is about 67 IF Update(fieldName) inside the trigger and a not very complex select statement inside the if followed by an insert to the audit table. When I leave only a few IF-s in the...
2
2524
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an Update statement. I have a sample code to reproduce my problem. To simplify the scenario I am trying to use Order related tables to explain a little better the tables i have to work with.
2
5266
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the user have to open a form and entera date so we know in report that the desiered check has been cleared. It takes me while to wrtie. But when I try to update the datagrid changes via dataset to MS Access 2003 I get an error that simply says...
8
3725
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: "Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21" 1/1/2005,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 1/2/2005,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
13
7674
by: abdoly | last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update that is the code private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) TextBox temp temp=(TextBox)e.Item.Cells.Controls String str=temp.Text; str always returnt the old value of the cell (before being updated) would u plz tell me about whats wrong i m doin
8
2698
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
1
2537
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code, no errors, but NO UPDATE I have to use ODBC I just need to update a field based on a key, EMBARASSED to say days going
5
3063
by: =?Utf-8?B?UlBhcmtlcg==?= | last post by:
I used the wizard to generate a typed dataset for my table and let it create my SPROCs. It created everything, and the GetData() method and the custom GetByUserName query works great, but when I try to call the Update() method of my TableAdapter, I get the following: "Procedure 'stp_SecurityUsers_Update' expects parameter '@userName', which was not supplied."
11
6069
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know if that's what's causing the behavior or not. It seems like the Update button should at least do something. When the Edit button is clicked, the grid goes into Edit mode and the Cancel button takes the grid out of Edit mode. So, I don't get what...
0
9489
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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
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
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.