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 > Common Table Expression in Update statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-28-09, 02:07
vinudba vinudba is offline
Registered User
 
Join Date: Aug 2009
Posts: 2
Common Table Expression in Update statement

Hi All

I have an update statement in which i am using a CTE (Common table Expression), but when i try to run its giving me syntax error. is CTE not supported inside update statements?. My db is Db2 V9.5 on Aix

My query is like the below.

update db2.tablename set col1=123 , col2='P'

where col3 in
( with temp 1 as (select a.col1,b.col2 from tableA A, tableB B where .....some conditions)
,
temp2 as (select a.col1 from tableA where ...some different conditions here)

select col1 from temp1 where temp1.col1=temp2.col1 where ....
)


SQL0104N An unexpected token "as" was found following "ol3 IN ( with temp1".
Expected tokens may include: "JOIN". SQLSTATE=42601

can some one please tell me why i am getting this error?
Reply With Quote
  #2 (permalink)  
Old 08-28-09, 02:39
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
"...with temp 1 as..."

is there a blanc between "temp" and "1" ? What happens if you omit it ?

Last edited by umayer; 08-28-09 at 02:43.
Reply With Quote
  #3 (permalink)  
Old 08-28-09, 02:57
vinudba vinudba is offline
Registered User
 
Join Date: Aug 2009
Posts: 2
actually there is no space in my query between temp and 1. it a typo while posting here. it's as temp1 in my original query.
Reply With Quote
  #4 (permalink)  
Old 08-28-09, 03:33
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
such syntax is not supported, use normal joins instead in subquery
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #5 (permalink)  
Old 08-28-09, 07:54
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Sometimes, you can use nested table expression insted of common table expression.

For example:

where col3 in
(
select temp1.col1
from (select a.col1,b.col2 from tableA A, tableB B where .....some conditions) AS temp1,
(select a.col1 from tableA where ...some different conditions here) AS temp2
where temp1.col1=temp2.col1 ....
)
Reply With Quote
  #6 (permalink)  
Old 08-28-09, 10:00
rdutton rdutton is offline
Registered User
 
Join Date: Dec 2008
Posts: 76
Or you could use a merge statement
__________________
RD
Reply With Quote
  #7 (permalink)  
Old 07-26-10, 11:23
rgrbrny rgrbrny is offline
Registered User
 
Join Date: Jul 2010
Posts: 3
Look here

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