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.
| 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) |
 |
|
|
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 Brett8-) |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-10-06 : 13:48:18
|
| math 101 states that if the result ofA - Bis negative, and you want a positive value, you can just calculateB - A- Jeff |
 |
|
|
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. :) |
 |
|
|
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 Brett8-) |
 |
|
|
|
|
|