CodingInCircles
CodingInCircles

Reputation: 2807

In clause in Select statement of SQL Server 2008

I have an SQL Server Query:

select *from table1 where column in ('list of values')

When I execute this, I get all the details, however, when I do this:

select *from table1 where column in ('list of values') and date_of_req='2011-03-15'

I get an empty table. All the column headings are there, but with no data. How to overcome this? I basically want to match all of those values in the IN clause and the date and display only that data.

Where am I going wrong?

Upvotes: 1

Views: 1757

Answers (3)

Shahid Altaf
Shahid Altaf

Reputation: 83

date_of_req have time part as well. So you can compare your date part of your column with below query

select * 
from table1 
where column in ('list of values') 
  and CONVERT(VARCHAR(10), date_of_req, 111) = '2011-03-15'

Upvotes: 0

Remus Rusanu
Remus Rusanu

Reputation: 294427

DATETIME likely has a time part too. Also, get in the habit of using the language insensitive datetime literal form ('YYYYMMDD') Try:

select *from table1 where column in ('list of values') 
and date_of_req=>'20110315'
and date_of_req < '20110316';

Upvotes: 4

Adam Dymitruk
Adam Dymitruk

Reputation: 129762

You probably have a time part as well. Ensure you are getting the date part out of date_of_req.

Upvotes: 3

Related Questions