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 > Record # for the rows displayed in DB2 query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-09, 04:18
Neena John Neena John is offline
Registered User
 
Join Date: Oct 2008
Location: India
Posts: 37
Record # for the rows displayed in DB2 query

Hi,
I need to write a query which selects some columns from a table with a
Serial number being displayed along with the other data from the table

For eg:
SNO Doc#
1 xxxyy
2 abcd
3 xyz


This SNO should be made to increment in the query itself.
Its like a numbering for the rows displayed.
Reply With Quote
  #2 (permalink)  
Old 08-04-09, 05:13
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
Olap functions:
row_number() over()
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #3 (permalink)  
Old 08-04-09, 07:27
Neena John Neena John is offline
Registered User
 
Join Date: Oct 2008
Location: India
Posts: 37
It is displaying the message
"The function ROW_NUMBER() not found"
Any other solution
Reply With Quote
  #4 (permalink)  
Old 08-04-09, 08:05
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
What is the Version of DB2 you are using and what is the operating system?
Reply With Quote
  #5 (permalink)  
Old 08-04-09, 16:57
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Neena John
It is displaying the message
"The function ROW_NUMBER() not found"
Any other solution
The post above did not provide the exact syntax you need to use for the OLAP function. Please check the SQL Reference manual to see if it is supported on your version of DB2, and to see exactly how to use the OLAP function.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 08-05-09, 03:04
Neena John Neena John is offline
Registered User
 
Join Date: Oct 2008
Location: India
Posts: 37
I am using DB2 verson 7
Reply With Quote
  #7 (permalink)  
Old 08-05-09, 03:04
Neena John Neena John is offline
Registered User
 
Join Date: Oct 2008
Location: India
Posts: 37
I am using DB2 verson 7
Reply With Quote
  #8 (permalink)  
Old 08-05-09, 04:12
ibm_db2_rocks ibm_db2_rocks is offline
Registered User
 
Join Date: Aug 2009
Posts: 8
$ db2 "select ROW_NUMBER() over() Row_Count, DEPTNUMB, DEPTNAME from org"

ROW_COUNT DEPTNUMB DEPTNAME
-------------------- -------- --------------
1 10 Head Office
2 15 New England
3 20 Mid Atlantic
4 38 South Atlantic
5 42 Great Lakes
6 51 Plains
7 66 Pacific
8 84 Mountain

8 record(s) selected.
Reply With Quote
  #9 (permalink)  
Old 08-05-09, 04:47
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Neena John
I am using DB2 verson 7
You did not state whether this is DB2 for z/OS or DB2 for Linux, UNIX, and Windows. Check the SQL Reference for your product to see if the row-number function is supported.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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