Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I built a query in MS Query / Excel, ending like this:
SQL
... AND (TSDD.PeriodEndDatePosted>={ts '2010-01-01 00:00:00'} And TSDD.PeriodEndDatePosted<{ts '2011-01-01 00:00:00'})

It works fine, note the {ts} at the end.
I then took this string:
SQL
... AND  (TSDD.PeriodEndDatePosted >= {ts '@FromDate@ 00:00:00'} AND  TSDD.PeriodEndDatePosted < {ts '@ToDate@ 00:00:00'}))

And did some Replace-ing to get:
SQL
... AND  (TSDD.PeriodEndDatePosted >= {ts '2010-01-01 00:00:00'} AND  TSDD.PeriodEndDatePosted < {ts '2011-01-01 00:00:00'}))


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

Conversion failed when converting datetime from character string.


So, why doesn't it work? And what is MS Query doing differently?
Posted
Comments
Sandeep Mewara 26-Jan-11 3:55am    
Nicely formed Q!

1 solution

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:
 
Share this answer
 
Comments
fjdiewornncalwe 25-Jan-11 18:19pm    
+5 for the honesty...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900