LIKE 之间的 SQL Server 日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8162006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:17:41  来源:igfitidea点击:

SQL Server date between LIKE

sqlsql-servertsql

提问by GreenCat

Please help me how to insert LIKE %in date between. Example is:

请帮助我如何LIKE %在日期之间插入。例子是:

SELECT * 
  FROM table 
 WHERE Date BETWEEN '" & startDate & "%'" AND '" & endDate & "%'" 

So in this code where i should put LIKEso that data will appear?

那么在这段代码中我应该放在哪里LIKE以便数据出现?

example if i set like this

例如,如果我这样设置

 SELECT * 
 FROM table 
 WHERE Date LIKE '" & startDate & "%'" 

it's working..LIKEmeant read either startdate or %..for starting it will read %

它正在工作..LIKE意味着读取 startdate 或 %.. 开始它会读取 %

回答by Ramandeep Singh

Try this :

尝试这个 :

"Select (listOfFields) 
 FROM TABLE
 where CONVERT(VARCHAR(25), Your_DATE, 126) BETWEEN 'Start_date%' AND 'EndDate%'";

回答by Nalaka526

Try something like this

尝试这样的事情

SELECT * from table 
WHERE CONVERT(VARCHAR, DateField, 120) BETWEEN  '2010%' AND '2012%'

回答by Steve Wellens

If the dates are of type string, you can't use BETWEEN*.

如果日期是字符串类型,则不能使用 BETWEEN*。

If the dates are of type date or datetime, you can't use LIKE.

如果日期是日期或日期时间类型,则不能使用 LIKE。

*Actually between might work with text because b is between a and c but it will not return correct results with date strings.

*实际上 between 可能适用于文本,因为 b 在 a 和 c 之间,但它不会返回带有日期字符串的正确结果。