![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Colleagues: Is possible to have an INCLUDE column in an UPDATE of a fullselect, something like: SNIP FROM FINAL TABLE ( UPDATE ( SELECT GRP_NUM, MIN(GRP_NUM) OVER (PARTITION BY EMPR_ID) FROM SESSION.NM_BAG ) AS NMB1 (GRP_NUM, MIN_GRP_NUM_FOR_EMPR) INCLUDE (OLD_GRP_NUM BIGINT) SET OLD_GRP_NUM = NMB1.GRP_NUM, NMB1.GRP_NUM = MIN_GRP_NUM_FOR_EMPR SNIP --Jeff Yes. UPDATE is the main reason for this feature, so you can pass out the |
#3
| |||
| |||
|
|
jefftyzzer wrote: Colleagues: Is possible to have an INCLUDE column in an UPDATE of a fullselect, something like: SNIP FROM FINAL TABLE ( UPDATE ( SELECT GRP_NUM, MIN(GRP_NUM) OVER (PARTITION BY EMPR_ID) FROM SESSION.NM_BAG ) AS NMB1 (GRP_NUM, MIN_GRP_NUM_FOR_EMPR) INCLUDE (OLD_GRP_NUM BIGINT) SET OLD_GRP_NUM = NMB1.GRP_NUM, NMB1.GRP_NUM = MIN_GRP_NUM_FOR_EMPR SNIP --Jeff Yes. UPDATE is the main reason for this feature, so you can pass out the OLD value using NEW/FINAL TABLE. Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab- Hide quoted text - - Show quoted text - |
#4
| |||
| |||
|
|
On Oct 10, 2:49 pm, Serge Rielau <srie... (AT) ca (DOT) ibm.com> wrote: jefftyzzer wrote: Colleagues: Is possible to have an INCLUDE column in an UPDATE of a fullselect, something like: SNIP FROM FINAL TABLE ( UPDATE ( SELECT GRP_NUM, MIN(GRP_NUM) OVER (PARTITION BY EMPR_ID) FROM SESSION.NM_BAG ) AS NMB1 (GRP_NUM, MIN_GRP_NUM_FOR_EMPR) INCLUDE (OLD_GRP_NUM BIGINT) SET OLD_GRP_NUM = NMB1.GRP_NUM, NMB1.GRP_NUM = MIN_GRP_NUM_FOR_EMPR SNIP --Jeff Yes. UPDATE is the main reason for this feature, so you can pass out the OLD value using NEW/FINAL TABLE. Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab- Hide quoted text - - Show quoted text - OK--thank you. So, in the example from the SQL Ref V2, below, where would the INCLUDE go? UPDATE (SELECT SALARY, COMM, AVG(SALARY) OVER (PARTITION BY WORKDEPT), AVG(COMM) OVER (PARTITION BY WORKDEPT) FROM EMPLOYEE) AS E(SALARY, COMM, AVGSAL, AVGCOMM) SET (SALARY, COMM) = (AVGSAL, AVGCOMM) WHERE EU.EMPNO = '000120' I ask because, using the code I asked about in my first post, I'm getting SQL0206N "OLD_GRP_NUM" is not valid in the context where it is used. LINE NUMBER=210. SQLSTATE=42703 when I try to create the SP. If you're saying it's OK to have an INCLUDE along with the UPDATE of the *fullselect*, then at least that rules that out as an issue; perhaps I'm just putting the INCLUDE in the wrong place. That would be a -104 (syntax error). |
#5
| |||
| |||
|
|
jefftyzzer wrote: On Oct 10, 2:49 pm, Serge Rielau <srie... (AT) ca (DOT) ibm.com> wrote: jefftyzzer wrote: Colleagues: Is possible to have an INCLUDE column in an UPDATE of a fullselect, something like: SNIP FROM FINAL TABLE ( UPDATE ( SELECT GRP_NUM, MIN(GRP_NUM) OVER (PARTITION BY EMPR_ID) FROM SESSION.NM_BAG ) AS NMB1 (GRP_NUM, MIN_GRP_NUM_FOR_EMPR) INCLUDE (OLD_GRP_NUM BIGINT) SET OLD_GRP_NUM = NMB1.GRP_NUM, NMB1.GRP_NUM = MIN_GRP_NUM_FOR_EMPR SNIP --Jeff Yes. UPDATE is the main reason for this feature, so you can pass out the OLD value using NEW/FINAL TABLE. Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab- Hide quoted text - - Show quoted text - OK--thank you. So, in the example from the SQL Ref V2, below, where would the INCLUDE go? UPDATE (SELECT SALARY, COMM, AVG(SALARY) OVER (PARTITION BY WORKDEPT), AVG(COMM) OVER (PARTITION BY WORKDEPT) FROM EMPLOYEE) AS E(SALARY, COMM, AVGSAL, AVGCOMM) SET (SALARY, COMM) = (AVGSAL, AVGCOMM) WHERE EU.EMPNO = '000120' I ask because, using the code I asked about in my first post, I'm getting SQL0206N "OLD_GRP_NUM" is not valid in the context where it is used. LINE NUMBER=210. SQLSTATE=42703 when I try to create the SP. If you're saying it's OK to have an INCLUDE along with the UPDATE of the *fullselect*, then at least that rules that out as an issue; perhaps I'm just putting the INCLUDE in the wrong place. That would be a -104 (syntax error). The statement looks sane to me. Could it be you have a local variable or parameter of the same name? Perhaps make sure that the names are unique. If that doesn't work I'd like to get a repro from you that I can play with. Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab- Hide quoted text - - Show quoted text - |
#6
| |||
| |||
|
|
Changing the line "AS NMB1 (GRP_NUM, MIN_GRP_NUM_FOR_EMPR)" to "AS NMB1"--that is, getting rid of the column names in the correlation clause--did the trick. Glad you got it to work. There is still something funny though and I'll |
![]() |
| Thread Tools | |
| Display Modes | |
| |