I'm rather new to SQL, and am working at upsizing a database from MS Access 2000. I was able to get the syntax right in Access for this problem, but I'm struggling with getting it right in SQL.
We have a text file that gets FTP'd nightly from a mainframe application. This is then imported into a table called tblErod. In order to bring it there, the text data type must be converted into a date-formatted field.
I've attempted working with both CAST and CONVERT. When I run it in the query analyzer, if I comment out the "INSERT INTO" statement, it runs without a problem. When I run it without commenting out that line, I receive this error: Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
Here's the dirty details:
This is what is used in MS Access 2000 that works:
INSERT INTO tblErod (field names) IN (MSAccess table location)
SELECT DateValue(Mid([strDateOpen],6,2) & "/" & Mid([strDateOpen],9,2) & "/" & Left([strDateOpen],4)) AS DateOpen1, DateValue(Mid([strDateCalled],6,2) & "/" & Mid([strDateCalled],9,2) & "/" & Left([strDateCalled],4))+TimeValue(Mid([strDateCalled],12,2) & ":" & Mid([strDateCalled],15,2)) AS Date2
I've converted it into SQL to this point:
INSERT INTO tblErod (field names)
SELECT CONVERT(DATETIME,Substring(strDateOpen,6,2) + '/' + Substring(strDateOpen,9,2) + '/' + Left(strDateOpen,4),101) AS dtmDateOpen, CONVERT(DATETIME,Substring(strDateCalled,6,2) + '/' + Substring(strDateCalled,9,2) + '/' + Left(strDateCalled,4)+ ' ' +
Substring(strDateCalled,12,2) + ':' + Substring(strDateCalled,15,2),101)AS dtmDateCalled,
FROM trwErod LEFT OUTER JOIN trwErodComments ON trwErod.strErodNum = trwErodComments.strErodNum
We have a text file that gets FTP'd nightly from a mainframe application. This is then imported into a table called tblErod. In order to bring it there, the text data type must be converted into a date-formatted field.
I've attempted working with both CAST and CONVERT. When I run it in the query analyzer, if I comment out the "INSERT INTO" statement, it runs without a problem. When I run it without commenting out that line, I receive this error: Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
Here's the dirty details:
This is what is used in MS Access 2000 that works:
INSERT INTO tblErod (field names) IN (MSAccess table location)
SELECT DateValue(Mid([strDateOpen],6,2) & "/" & Mid([strDateOpen],9,2) & "/" & Left([strDateOpen],4)) AS DateOpen1, DateValue(Mid([strDateCalled],6,2) & "/" & Mid([strDateCalled],9,2) & "/" & Left([strDateCalled],4))+TimeValue(Mid([strDateCalled],12,2) & ":" & Mid([strDateCalled],15,2)) AS Date2
I've converted it into SQL to this point:
INSERT INTO tblErod (field names)
SELECT CONVERT(DATETIME,Substring(strDateOpen,6,2) + '/' + Substring(strDateOpen,9,2) + '/' + Left(strDateOpen,4),101) AS dtmDateOpen, CONVERT(DATETIME,Substring(strDateCalled,6,2) + '/' + Substring(strDateCalled,9,2) + '/' + Left(strDateCalled,4)+ ' ' +
Substring(strDateCalled,12,2) + ':' + Substring(strDateCalled,15,2),101)AS dtmDateCalled,
FROM trwErod LEFT OUTER JOIN trwErodComments ON trwErod.strErodNum = trwErodComments.strErodNum