Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing char field into datetime field

Status
Not open for further replies.

DrewConn

Programmer
Jan 8, 2002
167
US
I am attempting to use a DTS job to import a csv file into a pre_existing table. The problem I have is the csv file has the dates stored as straight text with no /'s in them. (ie: 03062001) This is causing out of range errors on my import job.

What is the best way to get this type of data into a datetime field?

Thanks in advance.
 
You can do fancy stuff in DTS but a straighforward way would be to bring the CSV data into a 'PreWash' table that consists of pure char fields where there is problem data, then add a process to the dts to execute a stored proceedure that uses convert to rewrite the problem field into a valid date format, then INSERT it into your final destination table.

I am sure you could do the CONVERT in the DTS but someone else may be able to help with that one.

Cheers Dave Dave
dab@completebs.com
See website for more info but we can develop most things for most people.
 
DTS Transformations are quite simple. You can use VB or Java scripting. I prefer VB scripting. Here is an example that formats a date for insertion into a SQL table.

'**********************************************
' Visual Basic Transformation Script
' Copy each source column to the
' destination column
'**********************************************

Function Main()
Dim sDate

DTSDestination("PartNo") = DTSSource(1)
DTSDestination("Supplier") = DTSSource(2)

'transform date from mmddyyyy to yyyy-mm-dd format
sDate =
Right(DTSSource(3),4) & "-" &
Left(DTSSource(3),2) & "-" &
Mid(DTSSource(3),3,2)


If IsDate(sDate) Then
DTSDestination("PurDate") = sDate
Else
DTSDestination("PurDate") = Null
End If

DTSDestination("Quantity") = DTSSource(4)

Main = DTSTransformStat_OK
End Function

You can modify the transformations while creating the DTS package or after it has been saved you can open and edit it. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top