dbTalk Databases Forums  

Parse Text File before Import

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Parse Text File before Import in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
CB
 
Posts: n/a

Default Parse Text File before Import - 02-24-2005 , 09:35 AM






I am using a DTS package to import a text file that contains weblogs from
our firewall. I need to parse out one field before the import in sql2k. The
field contains the date yyyy-mm-dd 00:00:00. I would like to move the time
00:00:00 to a new column in the sql db.

Can any provide examples to do this?



Reply With Quote
  #2  
Old   
Joe
 
Posts: n/a

Default RE: Parse Text File before Import - 02-24-2005 , 10:03 AM






This is quite easy to achieve.

Not sure of you exact requirements, but this should be enough to head you in
the right direction.

If you text file has the format:

"Log Record One","2005-06-01 04:21:45"
"Log Record Two","2005-06-02 05:21:45"
"Log Record Three","2005-06-03 06:21:45"
"Log Record Four","2005-06-04 07:21:45"

To give you three field in a table, i.e.:

"Log Record One", "2005-06-01 04:21:45", "04:21:45"
"Log Record Two", "2005-06-02 05:21:45", "04:21:45"
"Log Record Three", "2005-06-03 06:21:45", "04:21:45"
"Log Record Four", "2005-06-04 07:21:45", "04:21:45"

Use a flat file source,an ole db destination and a transform data task
between them, delete the exitsting transformations and choose a new ActiveX
Script transformation.

You can then choose source and destination columns. When you've done that,
click properties to get you script editor open. And write something like the
following:


Option Explicit

Function Main()

DTSDestination("LogEntry") = DTSSource("Col001")
DTSDestination("LogEntryDate") = DTSSource("Col002")
DTSDestination("LogEntryTime") =
DATEPART("h",DTSSource("Col002"))&":"&DATEPART("n" ,DTSSource("Col002"))&":"&DATEPART("s",DTSSource(" Col002"))

Main = DTSTransformStat_OK

End Function

That should do you.

Let me know if it's not what your looking for.

Joe

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.