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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 MSSQL Select in time ranges

Author  Topic 

Raga
Starting Member

1 Post

Posted - 2010-06-12 : 16:25:31
Hello,
I want to SELECT some records in declared time range.

My table looks like that:

ID DATE
55 2010-06-12 21:49:00
56 2010-06-12 21:49:00
57 2010-06-12 21:49:00
58 2010-06-12 21:49:00
59 2010-06-12 21:49:00
60 2010-06-12 21:49:00
61 2010-06-12 21:49:00
62 2010-06-12 21:49:00
63 2010-06-12 22:01:00
64 2010-06-12 22:01:00
65 2010-06-12 22:01:00
66 2010-06-12 22:01:00
67 2010-06-12 22:04:47
68 2010-06-12 22:04:48
69 2010-06-12 22:04:49
70 2010-06-12 22:07:27
71 2010-06-12 22:07:27
72 2010-06-12 22:07:27


Query:
SELECT [id] FROM [dbo].[table] WHERE [date] >= '2010-06-12 21:49:00' AND [date] <= '2010-06-12 22:07:27'


Only this ID are returned:
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69


Why 70, 71, 72 IDs are not returned? There is
[date] <= '2010-06-12 22:07:27'


This works:
WHERE [date] >= '2010-06-12 21:49:00' AND [date] < '2010-06-12 22:07:28'


But why <= not?
Could you help me please?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-12 : 16:43:26
Because your datatime values for ID 70, 71 and 72 also have thousands of seconds within.
That's why the open-ended approach always works.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -