Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Finding absolute value

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2006-11-30 : 05:20:56

I have a field in a table where the values can be positive and negative but I want to get only the absolute value
Eg:
The field value can be -3 then the value to be returned is 3
/-3/ = 3 or if its 3 then it should return 3 itself

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2006-11-30 : 05:24:43
mmmmm.... the ABS function - returns absolute value

SELECT ABS(-13), ABS(3)


Duane.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-30 : 05:39:44
Damn. Why is the easy one already taken?

select case when sign(yourcolumn) < 0 then -1 * yourcolumn else yourcolumn end
from yourtable


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2006-11-30 : 05:40:08
Thanks totaly forgot...
Go to Top of Page
   

- Advertisement -