Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Tab Delimited file handling Expand / Collapse
Author
Message
Posted Wednesday, September 5, 2012 11:23 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, August 11, 2014 2:59 AM
Points: 330, Visits: 422
Hi,
I am new to Integration Services technology.
In SQL 2008 R2 Integration Services, We will be given Tab delimited Text files with million rows of records. I am in need to write a script to check the fields count againts the table fields count and have to separte the records which are not matching.
i.e. The records all are in need to be inserted into a table which will have a fixed number of fields. lets say 10.
Before inserting the records a validation has to be done for checking each record for the same count of fields(COLUMNS). The records which were not having the exact match are needed to get those records as separate output file

I need any of your help in start writing the script which is completely new to me.
Thanks !
Post #1355018
Posted Monday, September 10, 2012 3:15 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, August 11, 2014 2:59 AM
Points: 330, Visits: 422
Hi ! No one to help me ??
Post #1356605
Posted Monday, September 10, 2012 11:22 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Tuesday, September 2, 2014 10:53 AM
Points: 1,488, Visits: 479
Hello Here is one way.

Create Flat file Connection in SSIS setting the layout for 1Col

Create SQL Table:

CREATE TABLE dbo.Process_Table (
ID int identity(1,1) not null,
Column1 varchar(5000) null,
Nbr_Fields int null)

Import the whole record into the Process_Table field Column1

Update the nbr_Fields based on counting how many tabs there are in the record

Parse all the records that contain the correct number of fields into the appropriate table

Then you will also have all the records that didn't pass the validations, once the records are imported to the database table, you should be able to parse the records using SQL (substring to parse each column)

I didn't give you specifics as this should be relatively easy to do, writing the sql will be the most time consuming, any questions just reply to this thread and I will Help.

Post #1356912
Posted Monday, September 10, 2012 11:42 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Tuesday, September 2, 2014 10:53 AM
Points: 1,488, Visits: 479
Here is a function that you can use to count the tabs in a records:
--create this function first
CREATE FUNCTION [dbo].[ufn_CountChar] ( @pInput VARCHAR(1000), @pSearchChar CHAR(1) )
RETURNS INT
BEGIN

RETURN (LEN(@pInput) - LEN(REPLACE(@pInput, @pSearchChar, '')))

END
GO

--counts the nbr tabs in string
PRINT [dbo].[ufn_CountChar]('aaa aaa aaa ',char(9) )

Post #1356919
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse