Groups | Blog | Home
all groups > sql server connect > may 2005 >

sql server connect : convert from char(6) to datetime


Loane Sharp
5/9/2005 12:00:00 AM
Hi there

I receive a very much unstructured flat file, which I import into a SQL
Server database using DTS. After the import, one of the flat file columns is
in the format char(6) rather than datetime. The problem seems to be that the
text file column is in the format 'ddmmyy'. When I use the CONVERT statement
(ie. SELECT CONVERT(datetime, WEDate) As Expr1) I get the error message that
"The conversion of char data type to smalldatetime data type resulted in an
out-of-range smalldatetime value".

Any ideas?

Best regards
Loane

Steve Kass
5/10/2005 12:00:00 AM
Loane,

Try this (untested), using one of the format codes
from the Books Online article CAST and CONVERT:

CONVERT(datetime,RIGHT(WEDate,2)+SUBSTRING(WEDate,3,2)+LEFT(WEDate,2),12)

[quoted text, click to view]
AddThis Social Bookmark Button