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
 SQL Server Development (2000)
 Time Difference Negative-Pls guide

Author  Topic 

rahilshah
Starting Member

1 Post

Posted - 2004-10-06 : 13:03:37
Hello Everybody,
I am getting the difference of two values as negative. I want it to be positive. Is their any mod function in SQL Server to make it positive..



Set @TimeDiff= @SLAHrs-@TimeElapsedSec
= 800000-98657
= -186597

How do I set @TimeDiff as Positive?

Pls guide

Kapil

Bitz
Starting Member

19 Posts

Posted - 2004-10-06 : 13:09:32
Look at ABS()

Set @TimeDiff= ABS(@SLAHrs-@TimeElapsedSec)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-10-06 : 13:27:32
Really?


DECLARE @TimeDiff int, @SLAHrs int, @TimeElapsedSec int
SELECT @SLAHrs= 800000, @TimeElapsedSec = 98657
SET @TimeDiff= @SLAHrs-@TimeElapsedSec
SELECT @TimeDiff





Brett

8-)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-10-06 : 13:48:18
math 101 states that if the result of

A - B

is negative, and you want a positive value, you can just calculate

B - A


- Jeff
Go to Top of Page

Bitz
Starting Member

19 Posts

Posted - 2004-10-06 : 14:09:17
The problem is that you may not always know which one is the larger value. Is A always larger than B? Sometimes?

Take the example as a grain of salt. In addition to the example math being incorrect, the poster is subtracting seconds from hours. :)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-10-06 : 14:09:37
Or the other way around...



DECLARE @RS int, @A int, @B int
SELECT @A= 15, @B = 3
SET @RS = @A-@B
SELECT @RS
SET @RS = @B-@A
SELECT @RS




Brett

8-)
Go to Top of Page
   

- Advertisement -