Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rank Function in Mainframe DB2

Status
Not open for further replies.

pbibler

Technical User
Mar 30, 2005
18
US
I can't get the following query to work:

SELECT DIV_NO,ITM_NO, RANK() OVER (ORDER BY ITM_LAST_SH_DT) AS R1
FROM NOKDE.OKIITIO
WHERE ITM_NO= '15310'

It gives me a "Function Rank was not found" error. I thought Rank was an ANSI standard function. There's always the chance our system was modified somehow, because DB2 is the engine for our warehouse system, but any insights are welcome.

Thanks,

Paul
 
Rank is available for DB2 UDB from version 7 onwards (AFAIK)
Other types - OS400 - and mainframe do not support OLAP type functions

Ties Blom

 
I figured another way around it, but it's a nice function. Too bad. Thanks for your response, much appreciated.

Paul
 
Hi Sathyaram,

Are you back from a sabbatical?

Ties Blom

 
Sorry, I'll post the work-around, I never got an email that you had posted this. Basically, what I wanted to do was select only the row that had the most recent date. So I created a subquery from the same table which had the max(date):

SELECT a.DIV_NO,a.ITM_NO
FROM NOKDE.OKIITIO a,
(select div_no,itm_no,max(last_ship_dt) as maxdate
FROM NOKDE.OKIITIO a group by 1,2) b

WHERE a.div_no=b.div_no
and a.itm_no = b.itm_no
and a.last_ship_dt = b.maxdate

Crude, but effective. There might be a more elegant way, but this seemed to work well enough.
 
All,

For reference I've NEVER managed to get any of the OLAP functions RANK, ROW_NUMBER etc. to work on an OS390 type mainframe. The site I'm at at the moment is on DB2v8 and it doesn't work here either.

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top