SQL日期转换问题 [英] SQL Date Conversion Problem

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

问题描述

我在MS Query/Excel中建立了一个查询,结果如下:

I built a query in MS Query / Excel, ending like this:

... AND (TSDD.PeriodEndDatePosted>={ts '2010-01-01 00:00:00'} And TSDD.PeriodEndDatePosted<{ts '2011-01-01 00:00:00'})


效果很好,请注意最后的{ts}.
然后,我使用了这个字符串:


It works fine, note the {ts} at the end.
I then took this string:

... AND  (TSDD.PeriodEndDatePosted >= {ts '@FromDate@ 00:00:00'} AND  TSDD.PeriodEndDatePosted < {ts '@ToDate@ 00:00:00'}))


并做了一些替换以获得:


And did some Replace-ing to get:

... AND  (TSDD.PeriodEndDatePosted >= {ts '2010-01-01 00:00:00'} AND  TSDD.PeriodEndDatePosted < {ts '2011-01-01 00:00:00'}))



但是,当我尝试从ADODB.Command执行此操作时,我得到:



But when I try to execute this from an ADODB.Command I get:

Conversion failed when converting datetime from character string.



那么,为什么它不起作用? MS Query有何不同之处?



So, why doesn''t it work? And what is MS Query doing differently?

推荐答案

忽略我-我是笨蛋!

完成字符串替换后,如果您对查询使用修改后的字符串而不是原始的:doh:
Ignore me - I''m a dumbass!

Once you''ve done the string replacement, it helps if you use the modified string for the query, not the original :doh:


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

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