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
 General SQL Server Forums
 New to SQL Server Programming
 Get data sequnces duration

Author  Topic 

derach2000
Starting Member

37 Posts

Posted - 2009-12-16 : 05:38:15
Hi,

I have a table in which there are sequnces of the same data sorted by time. Something like this

datetime1 value1
datetime2 value1
datetime3 value2
datetime4 value2
datetime5 value1

and so on.

I need to get the duration of those sequnces with value2.
Is this possible witout sequential processing like cursors, or loops?

Regards

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-16 : 05:41:13
hi

Did you mean DATEDIFF function.

-------------------------
R...
Go to Top of Page

derach2000
Starting Member

37 Posts

Posted - 2009-12-16 : 05:56:47
yes datediff function would be used eventualy
but the problem is how to get the rigth rows to perform datediff...
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-16 : 05:58:41
I think it can achieved only by sequential processing!!


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-16 : 06:11:10
Try like this but i'm not sure about your Sequence

select aa.index_i,aa.s_no, datediff(mi,aa.login,bb.login) diff_in_min
from (select row_number() over(order by s_no) as index_i,* from(
select row_number() over(order by login) as s_no,
login from con_tbl_user_log ) a where s_no%2!=0 ) aa
inner join

(select row_number() over(order by s_no) as index_i,* from(
select row_number() over(order by login) as s_no,
login from con_tbl_user_log ) a where s_no%2=0) bb on aa.index_i=bb.index_i

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -