November 6, 2009 at 1:11 pm
Hi,
I have .txt that i am trying to load into sql table using SSIS2005
and the destination is SQL 2005.
The text file will have a header and data.
The format of the .txt will be as follows
CodeValues for the period ending 11/04/09
CodeValue
AZX123X
AZS143X
ADSE23V
This has to be loaded into a table with the date from the
header as a column
For example,
table format should be like this
CodeValue EndDate
AZX123X 11/04/09
AZS143X 11/04/09
ADSE23V 11/04/09
I am able to trim the hearder but not able to add this date column
from the header to the rows,
any ideas of to do this?
Thanks,
November 6, 2009 at 1:31 pm
I may give it a try if you can give the text file as attachment here, truncate the large portion of the data, so it can be a sample.
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
November 6, 2009 at 1:36 pm
Hi,
Please find the attachment.
Thanks,
November 6, 2009 at 1:38 pm
and this file have to be loaded to a table
as
Policy No Date
as the columns, and date values have to be populated from the header in the text file.
Thanks,
November 6, 2009 at 1:46 pm
Try loading the date from the header into a variable and then add a data transformation task for a derived colum. The value in the derived column that you will add will be your variable that holds the date in the variable.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
November 6, 2009 at 1:49 pm
Follow Jason's Suggestion that should work.
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
November 6, 2009 at 1:50 pm
CirquedeSQLeil (11/6/2009)
Try loading the date from the header into a variable ...
That's not as easy as you've made it sound - unless you know a method I haven't thought about. Were you thinking about using a script to read the first few lines and then using 'ignore first x lines' when reading the rest of the file in a standard DF?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 6, 2009 at 1:58 pm
CirquedeSQLeil (11/6/2009)
Try loading the date from the header into a variable .
Can you explain a little on how to do this? Please!
Thanks,
November 7, 2009 at 9:39 pm
Let me ask this... does it have to be done in SSIS? The reason I ask is because this is a trivial task in T-SQL.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 7, 2009 at 10:14 pm
Jeff Moden (11/7/2009)
Let me ask this... does it have to be done in SSIS? The reason I ask is because this is a trivial task in T-SQL.
Heh... see what I mean? 😛
--===== Create a temp table to import the file to
CREATE TABLE #AllData (RawData VARCHAR(8000))
--===== Import the data into a single column using all defaults.
BULK INSERT #AllData
FROM 'C:\Temp\SomeFile.txt' --This is where I saved the example file
--===== Declare some obviously named local variables
DECLARE @PeriodEnding DATETIME
--===== Populate a variable with the Period Ending date from the file header
SELECT TOP 1 --Just to short circuit the table scan...
@PeriodEnding = SUBSTRING(RawData,PATINDEX('%[0-1][0-9]/[0-3][0-9]/[2][0-9][0-9][0-9]%',RawData),10)
FROM #AllData
WHERE RawData LIKE '%FOR PERIOD ENDING [0-1][0-9]/[0-3][0-9]/[2][0-9][0-9][0-9]%'
--===== Return a result set with the CodeValue numbers and the Period Ending date...
SELECT LTRIM(RTRIM(RawData)) AS CodeValue,
@PeriodEnding AS EndDate
FROM #AllData
WHERE SUBSTRING(RawData,2,1) > ''
AND RawData NOT LIKE ' POLICY NO%'
I suppose you could even turn it into a stored procedure with a bit of dynamic SQL so you could pass the file you want to load as a parameter and run the stored proc from SSIS... but, all things considered, why even bother with SSIS? :hehe:
--Jeff Moden
Change is inevitable... Change for the better is not.
November 8, 2009 at 8:59 am
Nice solution Jeff.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 8, 2009 at 9:06 am
Jeff Moden (11/7/2009)
Jeff Moden (11/7/2009)
Let me ask this... does it have to be done in SSIS?
Yes, because my situation is more complex than what i have showed here.
Anyway this method might work me...
Thank you so very much, I will try this.
November 8, 2009 at 4:47 pm
UnionAll (11/8/2009)
Jeff Moden (11/7/2009)
Jeff Moden (11/7/2009)
Let me ask this... does it have to be done in SSIS?Yes, because my situation is more complex than what i have showed here.
Anyway this method might work me...
Thank you so very much, I will try this.
Thanks for the feedback but, heh, you're gonna give me whiplash... 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
November 8, 2009 at 4:49 pm
Phil Parkin (11/8/2009)
Nice solution Jeff.
Thanks, Phil. A lot of folks have asked why I haven't taken the time to learn SSIS. It's because of things like this...:-)
--Jeff Moden
Change is inevitable... Change for the better is not.
November 10, 2009 at 1:28 pm
This is perfect.
ThankYou again,
Thanks,
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply