简体   繁体   English

SQL Server 2008的Select语句中的In子句

[英]In clause in Select statement of SQL Server 2008

I have an SQL Server Query: 我有一个SQL Server查询:

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. 我基本上想匹配IN子句中的所有这些值和日期,并仅显示该数据。

Where am I going wrong? 我要去哪里错了?

DATETIME likely has a time part too. DATETIME也可能有时间部分。 Also, get in the habit of using the language insensitive datetime literal form ( 'YYYYMMDD' ) Try: 另外,养成使用对语言不敏感的日期时间文字形式( 'YYYYMMDD' )的习惯,请尝试:

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中获取日期部分。

date_of_req have time part as well. date_of_req也有时间部分。 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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM