IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Error in executing Query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rocky_balboa

New User


Joined: 24 Mar 2010
Posts: 61
Location: Cape of Good Hope

PostPosted: Tue May 25, 2010 10:05 pm
Reply with quote

Hi

I am getting error while executing the following query in QMF:

WITH TEST_TAB(MLB,TS) AS
(SELECT T1.AC_NR,T1.CUS FROM AAAAA.TAB AS T1 ORDER BY
T1.CUS DESC FETCH FIRST 2 ROWS ONLY)
SELECT MLB,MIN(TS) FROM TEST_TAB GROUP BY MLB ORDER BY MLB;

Following msg I am getting
------------------------------------------
SQL error at or before ORDER

Some common errors that produce this message are:

1. Use of the word DISTINCT more than once in a subquery.
2. Missing or inappropriate keyword or punctuation.
3. An unparenthesized subquery after select.

The line below lists one or more symbols that might have been correct,
based on the context so far, though they might not all work with the
whole query.

The list of alternate symbols are only suggestions. Some of the symbols
might not be legal statements for the database manager being used. Those
symbols might be correct for statements sent to other database managemen
systems.
) UNION EXCEPT

SQL Code: -199
---------------------------------------------
How can I resolve this?

Thanks
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed May 26, 2010 1:03 am
Reply with quote

Rocky,

Cannot use FETCH or ORDER BY inside full-select of CTE.
If you use will get -199.

Sushanth
Back to top
View user's profile Send private message
rocky_balboa

New User


Joined: 24 Mar 2010
Posts: 61
Location: Cape of Good Hope

PostPosted: Wed May 26, 2010 1:22 am
Reply with quote

Thanks!!!..

I had this inkling....because when I executed various forms of this query without an ORDER BY they were running fine....but I was not sure....

By the way...did you come to know of this by experience( like me).... or through a manual..... I tried searching the DB2 9 SQL manual for z/OS but could not find it...
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed May 26, 2010 1:49 am
Reply with quote

Well, first i tried then i got experienced.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed May 26, 2010 7:43 pm
Reply with quote

order by fetch first in a full select of the CTE works fine for me : DB2 V9 NFM
Code:
with biggest(dbid,name) as
(select  dbid, name from sysibm.sysdatabase
order by dbid desc fetch first 2 rows only)

select B.dbid, B.name,count(*) from biggest B, sysibm.systablespace A
where b.dbid = a.dbid
group by B.dbid, B.name
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed May 26, 2010 7:46 pm
Reply with quote

I am in DB2 V8.

Good to know it works in DB2 V9, Thank You GuyC for that information.



Sushanth
Back to top
View user's profile Send private message
rocky_balboa

New User


Joined: 24 Mar 2010
Posts: 61
Location: Cape of Good Hope

PostPosted: Wed May 26, 2010 9:48 pm
Reply with quote

Thanks Sushanth and GuyC for the information...actually I am also with DB2 V8 but was referring the V9 manual.....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Error when install DB2 DB2 2
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top