Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

create an aggregate function

Hello,

How can I create an aggregate function that receives a float as an input and outputs its absolute value?

Thanks

regards
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

Why you're looking for create this function, you have one called ABS: https://msdn.microsoft.com/en-us/library/ms189800.aspx
Avatar of bibi92

ASKER

Hello

Ok but how create this function?

Thanks

regards
you don't, it is created just use it
Avatar of bibi92

ASKER

I know I can use it, a user asks me to create a function to use it. Thanks
That the user asked for it does not mean that giving it to him/her is the right thing to do :)

One example, taking the sum of the absolute values:

SELECT Location, SUM(ABS(Sales)) AS AbsSales
FROM SomeTable
GROUP BY Location

Open in new window


OTOH, if you wanted the absolute value of the sum:

SELECT Location, ABS(SUM(Sales)) AS AbsSales
FROM SomeTable
GROUP BY Location

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibi92

ASKER

thanks regards