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 Programming
 Why do some datetime selects work but not others?

Author  Topic 

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-26 : 12:13:40
select * from winnebago
where ExecutionTime like '%2008%'


will return entries, but

select * from winnebago
where ExecutionTime like '%2008-08%'

will not.

i KNOW there are entries that contain 2008-08 in the table, for example

2008-08-24 16:38:00.000

btw the column is in datetime

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-08-26 : 12:19:24
try:
select * from winnebago
where datediff(mm, 0, ExecutionTime) = datediff(mm, 0, '20080801')
Go to Top of Page

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-08-26 : 12:21:18
or better yet

where ExecutionTime between '20080801' and '20080831 23:59:59.999'
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-26 : 12:49:01
because sql server doesn't know how to implicitly convert 2008-08 to a datetime

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-27 : 02:57:47
quote:
Originally posted by jdaman

or better yet

where ExecutionTime between '20080801' and '20080831 23:59:59.999'


or
where ExecutionTime >='20080801' and ExecutionTime <'20080901'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -