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 |
|
mlevier
Starting Member
33 Posts |
Posted - 2007-08-07 : 09:04:47
|
| I am trying to find out what the best SQL statement would be to find the next record based on a datetime field and grouped by telephone numbers. This is important because I need to know when the next call is within 24 hours. If the call is within the 24 hours then the Rep from the first call gets a 1 added in the repeat calls field. So I need a way to only find the next call in by that telephone number. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-08-07 : 09:24:49
|
| Maybe not the fastest but this is one wayselect t1.*, t2.*from calls t1left join calls t2on t1.number = t2.numberand t2.calldate = (select min(t.calldate) from calls t where t.number = t1.number and t.calldate > t1.calldate)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|