日期条件检查 [英] Date Condition Checking

查看:60
本文介绍了日期条件检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Iam使用sql server 2005作为我的后端



iam使用带有日期条件的查询。




Iam USing sql server 2005 as my back end

iam using query with date condition.

select * from Purchase v 
where cast( v.DocDate as datetime) >= cast('Sep 26 2014 12:00AM'as datetime ) 
and cast( v.DocDate as datetime) < cast('Aug 27 2014 12:00AM' as datetime)







执行上述查询时我无法得到任何结果



但是有记录。



你能告诉我我的错误吗?国王



谢谢



问候

Nirmala Sarvanan




when the above query is executed i cant get any results

but records are there.

Can u tell me what mistake iam making

Thanks

Regards
Nirmala Sarvanan

推荐答案

等等,您选择的文件是在9月26日之后和8月27日之前同时盖章的吗?只有当他们做那个量子时间旅行。



更新:对不起,我想这更像是一个讽刺的评论而不是解决方案。以下代码可以为您提供结果(交换您的运算符):



Wait, you're selecting documents that are simultaneously stamped after September 26th and before August 27th? Only if they do that quantum time travel.

UPDATE: Sorry, I guess that was more of a snarky comment than solution. Here is code that should get you your results (swapped your operators):

select * from Purchase v 
where cast( v.DocDate as datetime) <= cast('2014-09-26 12:00:00.000'as datetime ) 
and cast( v.DocDate as datetime) > cast('2014-08-10 12:00:00.000' as datetime)


试试这个



try this

select * from Purchase v
where convert(varchar,cast( v.DocDate as datetime),100) <= convert(varchar,cast('Sep 26 2014 12:00AM' as datetime),100)
and convert(varchar,cast( v.DocDate as datetime),100) >= convert(varchar,cast('Aug 27 2014 12:00AM' as datetime),100)


这篇关于日期条件检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆