Replace/Convert via sql while querying csv
I'm trying to query a CSV via ADODB/SQL and the resu开发者_运维知识库lts need to be ordered by date. The challenge is that the date is in dd-mon-yy format. I tried to use CONVERT and REPLACE but Excel 2003 keeps throwing Automation Error at me. I've tried both of the following separately.
With CONVERT:
"SELECT CONVERT(datetime,[Business Date],106) from [filename.csv]"
With REPLACE:
"SELECT REPLACE([Business Date],'-',' ') from [filename.csv]"
I don't have control over the CSV so manually correcting the dates is not an option.
How about:
SELECT CDate(Right([Business Date],2) & "/" _
& Mid([Business Date],4,3) & "/" _
& Left([Business Date],2)) from [filename.csv]
Depending, of course, on your locale. I do not believe Convert and Replace are available to ADO.
精彩评论