Solved

SQL Server SSIS - Flat File Import to Staging Table

Posted on 2010-08-24
5
1,414 Views
Last Modified: 2013-11-10
Hello,

I am importing a flat file source (csv) to a staging table, the flat file contains about 50 rows, and about 4gb of data.

Now, when I first define my flat file source, in the connection manager every row is defined a DataType of string [DT_STR] with a length of 50.

Is it suggested to use the "Suggest Type" button to have SQL define my rows or manually define them? Then, apply the same design to my staging table rows?

What is happening if I do use suggest type, then going straight to my database, I left SQL create the db, I get the following error:

Error: 0xC02020A1 at Stage Sales Extract, Flat File Source [41973]: Data conversion failed. The data conversion for column "COMMODITY" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".

The COMMODITY row in the CSV file is defined as eight-byte signed integer [DT_I8], and in the staging table it is defined as "bigint".

When I say I let SQL create the table, in the OLE DB Destination, when I click it I have the option to select a "New" table, and the code is predefined for me with the data types and lengths.

Should I be manually defining my Data Types from the CSV to the staging?

If so, anyone have an example of the data types that I should be assigning to my rows based on the data in there and the finally in the staging table design?

New to SSIS/SQL, this was a project thrown at me and I am trying to get through this.

If I use [DT_STR] when defining my CSV Data Type (this is numbers and characters?), this should be set as varchar(lenght) in the table design?

Thank you for your help.
0
Comment
Question by:mirde
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:vdr1620
ID: 33512840
I would suggest you to look at this Link, it maps SSIS data types to SQL Data types
http://msdn.microsoft.com/en-us/library/ms141036.aspx

If you are unaware of the Data or Length of Data in the File. I would suggest you to use (DT_STR) with length (as suggested) .. It is advisable to build your own table accordingly and then Select from the Table List in the OLE DB Destionation..

(DT_STR,12,1252) -- means that it is a string dataType, with length -12 and Codepage -1252 (Default) that should be transformed to Varchar(12) in SQL


0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 33513526
I generally take the approach that I have no expectations of my incoming data, so I import the data into a staging table that is completely defined as VarChar(xx).  Once it is in the saging table, I then do the manipulations, conversions, etc., in order to move it to the target table.
0
 

Author Comment

by:mirde
ID: 33513629
So your setting your staging table as VarChar(MAX) then fine tuning it when importing from the staging table (in my case) the production table?
0
 
LVL 22

Accepted Solution

by:
8080_Diver earned 250 total points
ID: 33513752
If I have absolutely no idea as to what the various field lengths are that I am dealing with, yes; however, if I have a "reasonable" estimate (for instance, I have reason to believe that few US cities have names longer than 64 characters), then I base things on that reasonable estimate (e.g. InboundCity VarChar(64)).  I also tend to allow NULLs in all of the columns because, if I am dealing with CSV files (which I frequantly am), the data bay be missing.  (I'd rather have a NULL in the staging table than have an arbitrary "default value". ;-)  Invariably, though, I will slightly over estimate the size of the column, if for no other reason than the "worst case scenario" planning.
If, for instance, I bring a payment amount into a varchar column, I can better copy with things like a leading $ or embedded commas (,) or, as with one I recently had to handle, leading hyphens/negative signs.  
0
 

Author Closing Comment

by:mirde
ID: 33649678
Thanks this has helped.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard 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.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in 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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

895 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

14 Experts available now in Live!

Get 1:1 Help Now