Solved

Trying to populate multple tables from a single source data file.

Posted on 2013-01-11
7
206 Views
Last Modified: 2016-02-11
I am trying to populate a bunch of tables from data that is contained in a single text file.  Not all target tables have the same number of columns.  The text file has rows of data, with the first piece of data telling which file type (which target table) the subsequent data in the row is for.  

See attached file for some sample data.

I tried just reading the source file into a single table, with the intent of parsing it and with t-sql and sending the rows of information to the appropriate target tables.  But I couldn't get the import wizard to read the text file.  It complained that the data was being truncated.  I went in and adjust the field lenghts (it thought there were 3 fields) to the maximum, 255.   But to no avail, it still would read it.

Thanks for your help!

Cipirano

Attached file has some data, and below are a few rows:

REC_TYPE_1|1|3.0
REC_TYPE_2|1|20120927 08:49:00|101|234223444|19750101|M|Brian|ODYSSEY|0513782||BEACH,BRIAN||||JOSEPH|ODYSSEY|025676||||||||||||SATURN MAIN theater|0513782|28497469||101
REC_TYPE_3||||||||1|13|ADV|||||||||||BEACH|||||||||ENGLISH
REC_TYPE_4|234227744|19990101|M|BRIAN||||BEACH,BRIAN
REC_TYPE_5|FOOD||3|||||JOSEPH|ODYSSEY|025676||0|||0|0.0||||1||||JOSEPH|ODYSSEY|025676|||||||||||||||||||||||||||||||||N|||| N/A|No upcoming days.|||||1||ADV||||||||0|102||111
REC_TYPE_6||||JOSEPH|ODYSSEY|025676|||Prelude
REC_TYPE_6||||JOSEPH|ODYSSEY|025676|||Hotel
REC_TYPE_6||||JOSEPH|ODYSSEY|025676|||Plant
REC_TYPE_7|||||
0
Comment
Question by:cipriano555
  • 4
  • 2
7 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 38769216
You can do this with the Conditional Split Transformation in SSIS:
Conditional Split Transformation
http://msdn.microsoft.com/en-us/library/ms137886(v=sql.90).aspx
0
 

Author Comment

by:cipriano555
ID: 38770128
I'll try that, sounds promising...guess if I can get it to take the pipe as the delimiter it seems to be perfect.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38770226
guess if I can get it to take the pipe as the delimiter it seems to be perfect.
Absolutely.  You can use any delimiter you like.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38770234
The trick is to come up with a key to be able to join all these rows after the fact.  There are a couple of ways to do that:
1. Use a key common to all the records.
2. If there is no common key, create a surrogate and add it to all the outputs.  This could be as simple as an incrementing value (1, 2, 3, ...)
0
 

Author Comment

by:cipriano555
ID: 38779603
It doesn't read the records in correctly.  I specified | as the delimiter.  REC_TYPE_1 as you see above has 3 fields.  So, it appears to think all records have 3 fields and so, for example, REC_TYPE_3 has tons of |'s in its third field. I hate to do a manual fix but in desperation I inserted a first row that has the maximum number of fields anticipated.  It looks like this:

header|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

But now I think it is not recogizing the start of a new row correctly.  And there are still columns which contain bunches of |s. So it is not always using | as a field delimiter.

Please see attached image.

I think my kludge (puting in a rows of ||||| at top)  is not really helping.
SSIS-Not-Recognizing-Next-Record.JPG
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38780368
You need to read up on the Conditional Split Transformation.  You are clearly not using it and you will not be able to import your file that way.

If you need a tutorial on how to use it, I will see if I can find something.
0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 38781353
1. First Take the Whole file data to temp table in database and iterate each row as you require.

Take each column value in variables and insert to your desire table based on condition.

As Above said you can use Conditional split. Or Condition in Direction.

If @Variable == 1 then This way
else second way...
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
My client sends data in an Excel file to me to load them into Staging database. The file contains many sheets that they have same structure. In this article, I would like to share the simple way to load data of multiple sheets by using SSIS.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now