If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Mainframe:Join in UPDATE statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-14-09, 11:40
ontheDB ontheDB is offline
Registered User
 
Join Date: Sep 2003
Posts: 80
Mainframe:Join in UPDATE statement

I'm in a mainframe environment. Using IBM DB2.

Below are the tables and columns I am working with:
Table A: Key1, Points
Table B: Key1, Key2
Table C: Key2, Points

I would like to update the Points column in Table A with the corresponding value from Table C.
However, since there is not a direct key which relates Tables A & C, I will have to do a join which relates all three tables.
Initially I tried the following:

UPDATE A
SET A.Points = C.Points
FROM A A
JOIN B B
ON A.Key1 = B.Key1
JOIN C C
ON B.Key2 = C.Key2


However, I get the error :
SQLCODE = -199, ERROR: ILLEGAL USE OF KEYWORD FROM. TOKEN ( .
MICROSECONDS MICROSECOND SECONDS SECOND MINUTES MINUTE WAS EXPECTED


I assume this is because a FROM statement is not allowed in this mainframe environment.

Anyone have any insight or suggestions for a workaround ?


Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 10-14-09, 11:55
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I do not know mainframe at all but this should work since it is standard SQL:

update a set points = (select c.points from b inner join c on (b.key2 = c.key2) where b.key1 = a.key1)

Andy
Reply With Quote
  #3 (permalink)  
Old 10-14-09, 12:47
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
The scalar-fullselect(Like in Andy's example) was supported on DB2 for z/OS Version 8 or later by looking into Manuals "SQL Reference" of Version 7/8/9.
Reply With Quote
  #4 (permalink)  
Old 10-14-09, 13:02
ontheDB ontheDB is offline
Registered User
 
Join Date: Sep 2003
Posts: 80
Quote:
Originally Posted by ARWinner
I do not know mainframe at all but this should work since it is standard SQL:

update a set points = (select c.points from b inner join c on (b.key2 = c.key2) where b.key1 = a.key1)

Andy
update a
set points =
(select c.points
from b inner join c on (b.key2 = c.key2)
where b.key1 = a.key1)

Hi,


I'll try the above SQL out; but my inital questions are:

1) will they be able to process what "a.key1" ? Isn't table a out of scope ?


thanks,
Reply With Quote
  #5 (permalink)  
Old 10-14-09, 14:27
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quote:
Originally Posted by ontheDB
1) will they be able to process what "a.key1" ? Isn't table a out of scope ?


thanks,
No it is not.

Andy
Reply With Quote
  #6 (permalink)  
Old 10-14-09, 16:20
rdutton rdutton is offline
Registered User
 
Join Date: Dec 2008
Posts: 76
This will not work in version 7, but will work in 8 or above (as indicated by tonkuma).
__________________
RD
Reply With Quote
  #7 (permalink)  
Old 10-15-09, 14:42
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
I don't know why it wouldn't work in 7, since it worked in 4, 5 & 6 and works agin in 8 & 9.
Dave
Reply With Quote
  #8 (permalink)  
Old 10-16-09, 03:52
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
The scalar-fullselect(Like in Andy's example) was supported on DB2 for z/OS Version 8 or later by looking into Manuals "SQL Reference" of Version 7/8/9.
Sorry, I was wrong.
DB2 for z/OS Version 7 doesn't support (scalar-fullselect) as a general expression.
But, it supports (scalar-fullselect)/(row-fullselect) in UPDATE statement.

This is a simplified syntax of UPDATE statement:
searched update:
UPDATE table-name | view-name [correlation-name] SET assignment-clause [WHERE search-condition] ...

assignment-clause:
column-name = expression | NULL | (scalar-fullselect)
or
(column-name[, column-name[...]]) = (expression | NULL[, expression | NULL[...]]) | (row-fullselect)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On