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 calcuation- how to do it???

Author  Topic 

Radhiga
Starting Member

35 Posts

Posted - 2006-04-13 : 08:24:48
Hai,
In my table activity starttime is in one row and endtime is in one row....
how can i find the difference between endtime-starttime...All the time i will have start time but i maynot have end time some time.....
guide me pls

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-04-13 : 08:39:27
with the info you provided:

select abs(sum(case when starttime then 1 else -1 end * isnull(time, 0))) as duration
from YourTable
group by commonId




Go with the flow & have fun! Else fight the flow
Blog thingie: [URL="http://weblogs.sqlteam.com/mladenp"]
Go to Top of Page

Radhiga
Starting Member

35 Posts

Posted - 2006-04-13 : 08:48:22
activity time
act1 20/05/02005 10:00:00
act2 20/05/2005 11:00:00

in my requirement act2 is the immediate next activity of act1. so time of act2-time of act1 is the duration of the act1 activity....
so i need to get the 60 mins as output for this....i believe u can understatnd
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-13 : 09:06:00
Select DateDiff(minute,startdate,endDate) from yourTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-13 : 09:38:17
Please post more sample data.



KH


Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2006-04-13 : 12:57:13
You need to be able to relate the "act1" record to the "act2" record through the data. Just the fact that one record occurs after the other isn't good enough, because SQL Server doesn't store the records in any particular order. You need another column that has the same data between them so you can do a join, or you need an identity column that guarantees that the second record sequentially follows the first record. Once you can correlate the two records, you can use DATEDIFF.
Go to Top of Page
   

- Advertisement -