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 > cte SQL0104N

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-11, 05:14
gjv gjv is offline
Registered User
 
Join Date: Oct 2011
Posts: 3
cte SQL0104N

i've a query which looks like..

"DELETE FROM session.t1 WHERE session.t1.col0 IN ( WITH my_scope AS ( SELECT result.col0 FROM session.t1 result), literals AS ...."

This fails with SQL0104N code..

[IBM][CLI Driver][DB2/NT64] SQL0104N An unexpected token "AS" was found following "0 IN ( WITH my_scope". Expected tokens may include: "JOIN". SQLSTATE=42601

not sure what is wrong being a new to Db2..any help is appriciated
Reply With Quote
  #2 (permalink)  
Old 10-17-11, 05:54
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by gjv View Post
i've a query which looks like..

"DELETE FROM session.t1 WHERE session.t1.col0 IN ( WITH my_scope AS ( SELECT result.col0 FROM session.t1 result), literals AS ...."
make it look like this:
Code:
WITH my_scope AS
   (SELECT result.col0 FROM session.t1 result)
DELETE FROM session.t1 
WHERE session.t1.col0 IN (select * from my_scope);
So, it is 1 statement but the CTE definition(2) come first.

I can only judge the CTE syntax. If all this works on temp-tables I do not know.
Reply With Quote
  #3 (permalink)  
Old 10-20-11, 02:14
gjv gjv is offline
Registered User
 
Join Date: Oct 2011
Posts: 3
thanks for looking into dr_te_z

i tried your suggestion but that failed with

"ODBC error. SQLSTATE: 42601 Native error: -104
Message: [IBM][CLI Driver][DB2/NT64] SQL0104N An unexpected token "DELETE FROM " was found following t1 result)

Appreciate suggestions
Reply With Quote
  #4 (permalink)  
Old 10-20-11, 02:22
gjv gjv is offline
Registered User
 
Join Date: Oct 2011
Posts: 3
one thing i would like to add is INSERT works fine with my previous query, now that is impacted with new approach..is there any diff with cte syntax for insert and delete
Reply With Quote
  #5 (permalink)  
Old 10-20-11, 05:10
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
... INSERT works fine with my previous query, ...
Analogy is a good starting point to study new things.
But, it would not give you an accurate conclusion.

You can't use common-table-expression in a DELETE statement.
See Syntax of DELETE statement in Information Center
DELETE - IBM DB2 9.7 for Linux, UNIX, and Windows


Anyhow, what result do you want to get by using common-table-expression?
Unless you want to use recursive-cte, you may get the intermittent result table without using cte.
Reply With Quote
Reply

Tags
cte db2 unexpected token

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