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 |
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2014-08-07 : 04:08:15
|
I've got a table that tracks when a person is holding a specific token, e.g.TokenId, PersonId, DateStart, DateEndI need to create a query to find which personId had a specific TokenId at the exact datetime specified.How could I do that?Thanks |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-08-07 : 07:56:32
|
[code]select PersonId from <yourtable>where TokenId = <a specific TokenId>and DateStart = <exact datetime specified>[/code] |
|
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2014-08-07 : 11:30:47
|
Hi,The datetime which is specified should match the row where that datetime falls anytime between datestart and dateend.Thanks |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-08-07 : 11:55:40
|
quote: Originally posted by Mondeo Hi,The datetime which is specified should match the row where that datetime falls anytime between datestart and dateend.Thanks
OK then:select PersonId from <yourtable>where TokenId = <a specific TokenId>and <datetime> >= datestart and <datetime> < dateadd(second, 1, dateend) |
|
|
|
|
|