all groups > sql server (microsoft) > november 2005 >
You're in the

sql server (microsoft)

group:

Looking at previous records


Looking at previous records stevebuy NO[at]SPAM eircom.net
11/23/2005 7:23:28 AM
sql server (microsoft):
Hi, I was hoping someone would point me in the right direction.

I have table with a few million records. Each record has a timestamp
field.
I want to be able to calculate what is the average time between all the
timestamps in the table.
It is further complicated by needing to remove from the averaging,
places where the gap between successive timestamps is very large. Most
timestamps occur within a few minutes of each other, but I would need
to remove from the averaging, where timestamps only occur every few
hours.

Many thanks in advance for any help on the matter.

SteveB.
Re: Looking at previous records Peter Nolan
11/24/2005 1:07:25 AM
Steve,
though you could write a piece of SQL to do this. If you want to do it
on a regular basis you would be better off going with writing a piece
of code that reads through a sorted view and calculates the number of
seconds (or milliseconds) between one row and the next...it could then
throw the result into a new work table....this will be much easier to
query and the results will be persistent.......such a piece of code
would be pretty trivial to write if you already have code reading
tables etc..

Peter
www.peternolan.com
Re: Looking at previous records stevebuy NO[at]SPAM eircom.net
11/25/2005 12:56:06 AM
Thanks for the reply Peter.
I have since written a cursor that writes the time difference into a
new work table.
Is this similar to what you are talking about or should I use some
proper VB code and recordsets?

SteveB
Re: Looking at previous records Peter Nolan
11/28/2005 9:33:51 AM
Hi Steve,
well, since I am not sure of your situation I don't know the best
language to write it in for you.....if you can do it in some form of
stored procedure using cursors and are able to calc the difference like
that it may be good enough.....

(Personally, I do just about everything like this in C++....but then
again I have a whole library of classes and pre-existing code as a base
to work from.....)

Best Regards
Peter
AddThis Social Bookmark Button