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
 General SQL Server Forums
 New to SQL Server Administration
 use datetime as a condition in where clause

Author  Topic 

honee
Starting Member

5 Posts

Posted - 2011-05-17 : 09:25:37
hi!
i am using datetime in whereClause but the problem is that it is not displaying any results. here is the query
select * from Comments where SendTime='4/2/2011 11:57:25 PM'
wher sendTime is the field of datatype datetime
and an other query which is also not working is
select * from Comments c,Rating r where c.SendTime=r.SendTime

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-05-17 : 09:38:19
It may be that the times are not matching EXACTLY. datetime data type stores milli-second part also (although the precision is only something like 3.33 millisecond or so). For example, the time stored might be this: '2011-04-02 23:57:25.667'

To test, you can change the where clause to this and see if that gets you anything:

where SendTime between '4/2/2011 11:55:25 PM' and '4/2/2011 11:59:25 PM'
which gives a 2-second window.

In your second statement, the problem is likely to be the same - i.e., the times do not match exactly.
Go to Top of Page
   

- Advertisement -