0

enter image description here

I have data based on column id and date...Data Type for date is DATETIME

DataBase : sql server 2008

Query 1:

Select * 
from table t1 
where (t1.date between '2016-05-11' and  '2016-05-13')

Query 2:

select * 
from table t1 
where t1.date IN ('2016-05-11')

Result is NUll even i have records on this date

So is there any Alternative to fetch records except (<=/</>/>=) greater than or less than

Jaydip Jadhav
  • 12,179
  • 6
  • 24
  • 40
Vivek Gondliya
  • 308
  • 1
  • 2
  • 15

2 Answers2

0

You can use below query but your query is also correct and its running on my server.

Select * from table t1 
where t1.date between '20160511 00:00:00' and '20160513 23:59:59';

select * from table t1 where cast(t1.date as date) IN ('20160511');
Sandeep Kumar
  • 1,172
  • 1
  • 9
  • 22
0

Try this,

Select * 
from table t1 
where cast(t1.date as date) between '2016-05-11' and  '2016-05-13'

ie Convert your datetime column to date and compare, because your parameters are only date values. or

where cast(t1.date as date) in ('2016-05-11')--For your second query

or use greater than or less than

Select * 
from table t1 
where t1.date >= '2016-05-11' and  t1.date < '2016-05-14'
Abdul Rasheed
  • 6,486
  • 4
  • 32
  • 48