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 |
|
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 durationfrom YourTablegroup by commonIdGo with the flow & have fun! Else fight the flow Blog thingie: [URL="http://weblogs.sqlteam.com/mladenp"] |
 |
|
|
Radhiga
Starting Member
35 Posts |
Posted - 2006-04-13 : 08:48:22
|
| activity time act1 20/05/02005 10:00:00act2 20/05/2005 11:00:00in 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 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-04-13 : 09:06:00
|
| Select DateDiff(minute,startdate,endDate) from yourTableMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-13 : 09:38:17
|
Please post more sample data. KH |
 |
|
|
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. |
 |
|
|
|
|
|