SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Unstructured File with Header, Detail, Trailer
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rka
Starting Member

Australia
6 Posts

Posted - 05/31/2012 :  10:35:17  Show Profile  Reply with Quote
I have a flat file (pipe delimited) which I want to import into a table. The file format is based on Header, Detail and Trailer and is structured as:

quote:
H|20120531|SAPECC6|
D|CostCentreID|CostCentreName|CostCentreDescription|
D|700|Name1|Description 1|
D|701|Name2|
D|702|Name3|Description 3|
D|703|Name4|
T|4|




The First Row represents Header (H) which contains ExtractDate and SourceSystemName
The Second row represents the Column Names for the Detail Rows
There are 4 Details (D) rows containing the data
The Trailer(T) row contains the count of data in the Detail rows

If the file is treated as an "unstructured file" e.g. the 2nd and 4th detail row does not have description, how can the data be imported into a destination table which looks like this:


CostCentreID  CostCentreName   CostCentreDescription  SourceSystem ExtractDate
700               Name1                Description1   SAPECC6       2012-05-31
701               Name2                               SAPECC6       2012-05-31
702               Name3                Description3   SAPECC6       2012-05-31
703               Name4                               SAPECC6       2012-05-31



And finally, I want to validate the number of rows loaded against the Trailer Recod which was 4 (This acts as a reconciliation)

Can anyone help me with this?

Thanks

Edited by - rka on 05/31/2012 10:36:42

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 06/04/2012 :  18:58:36  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
1. is there always a trailer record per file being ingested?
2. after validation against T|4| what do you want to do?
3. any chance you can get this crap of data as xml?
4. will the file structure and/or values stay the same?

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion

Edited by - yosiasz on 06/04/2012 19:12:48
Go to Top of Page

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 06/04/2012 :  19:27:04  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote

create table dbo.rka(CostCentreID int, CostCentreName varchar(50), CostCentreDescription varchar(50), SourceSystem varchar(50), ExtractDate datetime)

ingest to a staging table named CostCenter

insert into dbo.rka(CostCentreID , CostCentreName, CostCentreDescription , SourceSystem, ExtractDate )
SELECT cs1.[COLUMN 1], cs1.[COLUMN 2], cs1.[COLUMN 3], a.[COLUMN 2], CAST(a.[COLUMN 1] AS DATETIME)
  FROM [dbo].[CostCenter] cs1
  cross apply (SELECT [COLUMN 1], [COLUMN 2] FROM [dbo].[CostCenter] cs1 where [COLUMN 0] = N'H') a
  where ISNUMERIC(cs1.[COLUMN 1]) = 1
  and cs1.[COLUMN 0] = 'D'


<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion

Edited by - yosiasz on 06/04/2012 19:41:51
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000