Page 1 of 1

MAx of two negative decimal

Posted: Thu Feb 12, 2009 1:53 am
by consulting
My requirement is I want to find the max of two negative decimals
for eg;

max(-89.62,-88.02) I want the output as -89.62

but I am getting 0 The output feils data type is decimal(10,2)

Can you please help me

Posted: Thu Feb 12, 2009 3:26 am
by vjonnala1516
It has to work, check the data just before the comparision.

Posted: Thu Feb 12, 2009 6:23 am
by Mike
You have stated your requirement incorrectly based on your example. Perhaps a correct requirements statement will guide you to a proper solution.

What seems to be your requirement:
When comparing two negative numbers, choose the value having the largest absolute value.

Mike

Posted: Thu Feb 12, 2009 8:23 am
by throbinson
I've never used this function and if I had a dime for all the times things "have to work" but didn't I wouldn't be sitting here writing this. I have, however, used the help button in Datastage.
To wit;
Max

Code: Select all

 Returns the greater of the two argument values
 number 1 (int32) number 1 (int32)
 result (int32)
 
I'm thinking decimals are not allowed for this function.

Re: MAx of two negative decimal

Posted: Thu Feb 12, 2009 8:50 am
by chulett
consulting wrote:My requirement is I want to find the max of two negative decimals
for eg;

max(-89.62,-88.02) I want the output as -89.62
As noted, the 'max' of those two values is -88.02 as -89.62 is less than -88.02.

Posted: Thu Feb 12, 2009 2:03 pm
by ray.wurlod
Remember back at school, when they taught you about the number line?

As Craig observed, -89.62 is less than -88.02. Therefore the Max() function is yielding the correct result.

You need to consider what you really want. It sounds like you want the number with the larger absolute value. (If you can be certain that both numbers are negative, this is - of course - given by the Min() function. Otherwise, something like Max(Abs(FirstNumber),Abs(SecondNumber)) is what you need.)

Posted: Thu Feb 12, 2009 2:12 pm
by throbinson
He wants -89.62 but is getting zippage. Will max() work with a decimal?