通过比较日期字段检索时出现问题 [英] problem while retrieving by comparing datefield
问题描述
我有一个名为student的sql表,并且在表"dat"中有一个字段,当我在编写诸如... select * from student where dat=''01-05-2011''
之类的查询时,该字段的类型为date,它没有显示任何内容,但实际上是具有该日期的记录表格中有表格.....我已经尝试了很多事情,但我做不到
i have a sql table named student and a field in the table "dat" which is of type date when i m writing a query like...select * from student where dat=''01-05-2011''
,it is not showing anything,but actually a record having this date is there in the table.....i have tried many things but i can not do it
推荐答案
如何尝试限制查询的准确性呢?而不是使用:
How about if you try and limit your query accuracy. Instead of using:
SELECT * FROM student WHERE dat= '2011-05-01';
尝试使用这样的范围(使用``=>''代替``=''):
Try using a range like so ( using ''=>'' instead of ''='' ):
SELECT * FROM student WHERE dat=> '2011-05-01';
警告!这应该取决于要检索的数据,如果要检索精确匹配,则解决方案1是最好的选择,否则请选择解决方案2.
祝您编程愉快,
Morgs
Caution! this should depend on what data you would like to retrieve, if you want to retrieve an exact match then solution 1 is your best bet otherwise go wild and use solution 2.
Happy coding,
Morgs
在进行比较之前,尝试将两种数据转换为一种格式.查看我的代码:
Try converting both data to one format before comparing. See my code:
SELECT * FROM student WHERE CONVERT(date, dat,101) = CONVERT(date, '2011-05-01', 101)
如果这解决了您的问题,请标记为答案并投票5
问候,
爱德华(Eduard)
Please mark as answer and vote 5 if this solved your problem
Regards,
Eduard
尝试使用ISO格式的日期:yyyy-MM-dd:
Try using ISO format dates: yyyy-MM-dd:
SELECT * FROM student WHERE dat='2011-05-01'
这篇关于通过比较日期字段检索时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!