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 matc开发者_StackOverflow社区h all of those values in the IN clause and the date and display only that data.
Where am I going wrong?
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';
You probably have a time part as well. Ensure you are getting the date part out of date_of_req.
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'
精彩评论