Re: How to write date transform script
- From: "Richard Lewis Haggard" <HaggardAtWorldDotStdDotCom>
- Date: Sun, 4 Dec 2005 21:13:10 -0500
For future reference, here's how to do it. It turns out to be quite easy and
even locale safe. The trick is to use DateSerial and feed it the appropriate
data. It will take care of creating a datetime that will work with the
locale.
Function Main()
DTSDestination("Ticker") = DTSSource("Col001")
str = DTSSource("Col002")
iYear = CInt( Mid( str, 1, 4) )
iMo = CInt( Mid( str, 5, 2) )
iDay = CInt( Mid( str, 7, 2) )
DTSDestination("Date") = DateSerial( iYear, iMo, iDay)
DTSDestination("POpen") = DTSSource("Col003")
DTSDestination("PLow") = DTSSource("Col004")
DTSDestination("PHigh") = DTSSource("Col005")
DTSDestination("PClose") = DTSSource("Col006")
DTSDestination("Vol") = DTSSource("Col007")
Main = DTSTransformStat_OK
End Function
--
Richard Lewis Haggard
"Richard Lewis Haggard" <HaggardAtWorldDotStdDotCom> wrote in message
news:OSKGYuJ9FHA.476@xxxxxxxxxxxxxxxxxxxxxxx
>I have stock data files to import into a SQL table. Here's a line from one
>of the files:
>
> QQQ 19990311 51.43750 51.71850 50.31250 51.31250 90108.00000
>
> Each column is separated by a tab and the import wizard has no trouble
> understanding the data but, of course, it wants to import everything as a
> varchar. It would be nice to be able to transform the data at import time
> into something more appropriate. For example, the second column is
> YYYYMMDD and the following columns are floating point numbers. What should
> the syntax be to convert the YYYYMMDD to a date?
>
> The default script that the import wizard produces for the Column Matches
> and Transforms page is is
>
> Function Main()
> DTSDestination("Ticker") = DTSSource("Col001")
> DTSDestination("Date") = DTSSource("Col002")
> DTSDestination("POpen") = DTSSource("Col003")
> DTSDestination("PLow") = DTSSource("Col004")
> DTSDestination("PHigh") = DTSSource("Col005")
> DTSDestination("PClose") = DTSSource("Col006")
> DTSDestination("Vol") = DTSSource("Col007")
> Main = DTSTransformStat_OK
> End Function
>
> The table that is to receive the data is defined as
> Ticker char 4
> Date datetime
> POpen float
> PLow float
> PHigh float
> PClose float
> Vol float
>
> so there are some obvious problems with the import. I'd like to
>
> convert DTSSource("Col002") to a datetime
> convert the remaining columns to a float.
>
> What is the syntax needed to do this?
> --
> Richard Lewis Haggard
>
.
- Prev by Date: Re: Best place for SMO questions?
- Next by Date: Re: SSPI Error after a while
- Previous by thread: Best place for SMO questions?
- Next by thread: Re: SSPI Error after a while
- Index(es):
Relevant Pages
|