| |
|
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.
|
 |

11-23-04, 08:08
|
|
Registered User
|
|
Join Date: Jan 2004
Location: Europe, Finland, Helsinki
Posts: 60
|
|
Scalar MIN and MAX for UDB?
|
|
Hi!
DB2 z/OS V.7 has scalar funtions MIN and MAX*). Now DB2 UDB seems not to have those. So we have problem to port application.
Any ideas? These functions can be implemented by UDF, right? Are there any freeware or commercial packages?
Cheers, Bill
*) Normal column function use this syntax: MAX( ALL/ /DISTINCT expression).
Scalar function MAX has this syntax: MAX(expression, expression...).
|
|

11-23-04, 08:48
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
|
|
Quote:
|
Originally Posted by hurmavi
Hi!
DB2 z/OS V.7 has scalar funtions MIN and MAX*). Now DB2 UDB seems not to have those. So we have problem to port application.
Any ideas? These functions can be implemented by UDF, right? Are there any freeware or commercial packages?
Cheers, Bill
*) Normal column function use this syntax: MAX( ALL/ /DISTINCT expression).
Scalar function MAX has this syntax: MAX(expression, expression...).
|
Can you use the CASE statement?
ie. SELECT CASE WHEN A > B THEN A ELSE B END
FROM MYTABLE;
Kind of ugly.
__________________
--
Jonathan Petruk
DB2 Database Consultant
|
|

11-23-04, 08:56
|
|
Registered User
|
|
Join Date: Jan 2004
Location: Europe, Finland, Helsinki
Posts: 60
|
|
|
|
OK!
I think, CASE would work, allright.
However, since we have more than two columns to choose, result can really be pretty much ugly, indeed. Thank you, anyway - we'll use it, if no better solution will be found.
Cheers, Bill
|
|

11-23-04, 09:13
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
|
|
You could always bury it into a function:
CREATE FUNCTION SCHEMA1.NEWMAX
(VAL1 INTEGER, VAL2 INTEGER)
RETURNS INTEGER
LANGUAGE SQL
BEGIN ATOMIC
RETURN CASE WHEN VAL1 > VAL2 THEN VAL1
ELSE VAL2
END;
END @
__________________
--
Jonathan Petruk
DB2 Database Consultant
|
|

11-23-04, 10:00
|
|
Padawan
|
|
Join Date: Jun 2002
Location: UK
Posts: 525
|
|
... or hold your values in a CTE and use the column function.
Code:
with temptable (col1) as
(
values (1),(2),(0),(9)
)
select min(col1) from temptable
|
|

11-23-04, 11:41
|
|
Window Washer
|
|
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
|
|
Hold the phone...are you saying V8 doesn't have MIN and MAX?
|
|

11-23-04, 11:47
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
|
|
Quote:
|
Originally Posted by Brett Kaiser
Hold the phone...are you saying V8 doesn't have MIN and MAX?
|
It has MIN and MAX the column functions:
SELECT MAX(A) FROM MYTABLE;
(returns the biggest A)
But not the scalar function:
SELECT MAX(A,B) FROM MYTABLE;
(returns the larger of A or B for *each* columns)
__________________
--
Jonathan Petruk
DB2 Database Consultant
|
|

11-23-04, 11:55
|
|
Window Washer
|
|
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
|
|
Well it's glad that I didn't know that, now that it's going away...
Because it not ANSI?
Code:
SELECT MAX(NAME,TSNAME) FROM SYSIBM.SYSTABLES;
Amazing...
|
|

11-23-04, 11:59
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
|
|
Quote:
|
Originally Posted by Brett Kaiser
Well it's glad that I didn't know that, now that it's going away...
Because it not ANSI?
Code:
SELECT MAX(NAME,TSNAME) FROM SYSIBM.SYSTABLES;
Amazing...
|
I think it's sticking around in z/OS, but it's never existed that I can recall on Linux/Unix/Windows.
__________________
--
Jonathan Petruk
DB2 Database Consultant
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|