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 |
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-05-30 : 07:08:12
|
| How can I get the nearest time record based on the 3rd record?in MySQL I used like thisSELECT id, sampletime FROM tablename ORDER BY ABS(TIMESTAMPDIFF(SECOND, sampletime, '2007-05-23 16:40:00')) ASC LIMIT 1 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-30 : 07:18:42
|
| Select top 1 * from @T1order by abs(datediff(s, tcol4, '2003-01-04 00:00:40.000'))--------------------------------------------------S.Ahamed |
 |
|
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-05-30 : 07:21:03
|
| thnx |
 |
|
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-05-30 : 07:33:43
|
| not jet..by the following querySelect top 1 * from NF_DATAorder by abs(datediff(s, sampletime, '2007-02-21 12:25:09.000'))I get the record where the time is '2007-02-21 12:25:09.000' |
 |
|
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-05-30 : 07:42:11
|
| Now it works :)select max(SampleTime)from NF_DATAwhere SampleTime in (Select top 2 SampleTime from NF_DATA order by abs(datediff(s, sampletime, '2007-02-21 12:25:09.000')) ) |
 |
|
|
|
|
|