Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arithmetic in SQL Trigger - Pulling out hair! :( 1

Status
Not open for further replies.

mobbarley

IS-IT--Management
Mar 4, 2004
22
0
0
AU
Hi guys,

I have an SQL database with a trigger to fill in some extra data from other tables when a record is inserted. One task is to add a time (in minutes) to a DATETIME field.

Here is a extract:
DECLARE
@varTimeAdjustment DATETIME
SELECT
@varTimeAdjustment = (select LogTime from INSERTED) + 1/1440 * (Select ResponseTime from ProblemCodes where Ref = (select ProblemRef from INSERTED))


Now, the ResponseTime query comes back as 15 [minutes]. If i have it just LogTime + Response time it adds 15 days (close!) so Im trying to use 1/1440 as that is 1/mins in a day.
However, when i put the 1/1440 in, i have tried several different ways, it records exactly the same time, as if it was adding 0!

This is driving me crazy! Please help almighty sql gods.
 
Integer math - use 1.0/1440 or 1/1440.0 instead...

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Thanks vongrunt! Did the trick. Is there a better way to add (x) minutes to a DateTime field? I'll have to check but i think the seconds are a little out of whack due to rounding? But this will work, I dont need to the second precision.
 
Two other ways:
Code:
myDate + '00:01:00'

DATEADD(mi, 1, myDate)

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top