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

Error while numbering returned rows sequentially


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

New User


Joined: 09 Jan 2008
Posts: 25
Location: India

PostPosted: Thu Feb 28, 2008 6:10 pm
Reply with quote

I want to number the returned rows from a select query sequentially.

SELECT C_ID,S_SEQ,
ROWNUMBER() OVER (ORDER BY S_SEQ DESC) AS NUM
FROM VNT;

I am getting the following error:

SQLCODE = -104, ERROR: ILLEGAL SYMBOL "(". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: , FROM INTO


Can any one please correct my query.
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Thu Feb 28, 2008 6:19 pm
Reply with quote

Code:
ROWNUMBER()

OVER (...)

Are these two user defined functions?
Back to top
View user's profile Send private message
Kiranmayee

New User


Joined: 09 Jan 2008
Posts: 25
Location: India

PostPosted: Thu Feb 28, 2008 6:24 pm
Reply with quote

No they are not user defined. I searched in net and got his syntax.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Feb 28, 2008 6:57 pm
Reply with quote

For which vendors version of SQL?
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Thu Feb 28, 2008 7:05 pm
Reply with quote

Is this okay?
Code:
SELECT C_ID,
S_SEQ,
ROW_NUMBER() OVER (ORDER BY S_SEQ DESC) AS NUM
FROM VNT;
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Feb 28, 2008 7:31 pm
Reply with quote

I think your net search was wrong. That seems more like Oracle syntax to me.

Have you looked in the DB2 SQL Reference Manual? I did a search of it for Row_Number and it returned 0 results for it as a function to number rows. I also did OVER( and got no results.
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Thu Feb 28, 2008 7:40 pm
Reply with quote

I got these info by google-ing through.

ROW_NUMBER() OVER (...) is a OLAP function available with DB2 for UNIX, Windows, and OS/2 as I guess.

And

ROW_NUMBER() OVER tells DB2 how you want the rows numbered. If you are selecting Employee data, telling it to ROW_NUMBER() OVER (ORDER BY SALARY DESC) would have the row with the highest SALARY as #1, the second highest as #2, etc.

Select the exact same data with ROW_NUMBER() OVER (ORDER BY LASTNAME) would have a person with a LASTNAME starting with 'A' as #1 and someone with 'Z' as the very last.

Please try these links.

www.ibm.com/developerworks/db2/library/techarticle/lyle/0110lyle.html

www.ibm.com/developerworks/db2/library/techarticle/dm-0401kuznetsov/index.html
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 To get the count of rows for every 1 ... DB2 3
No new posts Error when install DB2 DB2 2
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
Search our Forums:

Back to Top