I am using SQL Server 2000.
when I am querying data from following query it gives an error.
Query: select * from SaleMain where dateinfo<='2008-02-25'
and dateinfo>='2008-02-25'
error: Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
And occour the same error for : select * from SaleMain where dateinfo<=cast('2008-02-25' as datetime)
and dateinfo>=cast('2008-02-25' as datetime)
But when I am using this query it works:
select * from SaleMain where dateinfo<=cast('2008-02-25 00:00:00.000' as datetime)
and dateinfo>=cast('2008-02-24 00:00:00.000' as datetime)
And then I try this query and works fine: select * from SaleMain where dateinfo<=cast('2008-02-25' as datetime)
and dateinfo>=cast('2008-02-25' as datetime)
And also this query works after that: select * from SaleMain where dateinfo<='2008-02-25'
and dateinfo>='2008-02-25'
Actually I am amazed with this functionality. And I have experience in this type of adhoc behavior for datetime in earlier also.
Can anyone please tell me, is there any sure and a very accurate way of writing these type of queries those are using datetime values.