Converting data types in SSIS - sql

I get an input CSV file that I have to upload to my oracle database.
Here is some sample data
ContractId, Date, HourEnding, ReconciledAmount
13860,"01-mar-2010",1,-.003
13860,"01-mar-2010",2,.923
13860,"01-mar-2010",3,2.542
I have to convert the incoming column to DB_TIMESTAMP (to match the structure in the destination table).
But when I use Data Conversion to convert, I get an error
Data conversion failed while converting column "Date" (126) to column "Date" (496). The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.
What should I do to be able to properly convert this data?

What you could do in this situation is change the Text Qualifer in your Flat File connection to be a single double quote (").
This will cause SSIS to interperet
13860,"01-mar-2010",1,-.003
as
13860,01-mar-2010,1,-.003
This also has the added bonus of being able to catch any embedded commas in your data if they are also qualfied with quotes.

The problem is with the quotation marks ["] in the file.
You should remove them from the file or add a Derived Column before the Data Conversion component to remove the " with the expression
REPLACE([TextDateColumn],"\"","")

Related

How to resolve SSIS Package Truncation error

SSIS Error: 0xC02020A1
Tying to import data to SQL 2008 from CSV file, I am getting below error.
> Error: 0xC02020A1 at Data Flow Task, Source – Distribution by xyz
> table from CSV [1]: Data conversion failed.
> The data conversion for column "ID" returned status value 4 and
> status text "Text was truncated or one or more characters had no match
> in the target code page.".
previous have used varchar and never a problem, I have tried to convert data to Int and even increased the size but still getting this error. I have also tried using the Advance editor and changed data to almost anything I could think would cover datatype on that column, still getting an error. Thanks for the advice
Most likely you have "bad" records in your raw file.
For "bad", if could be one of these two: 1) implicitly conversion cannot be done to the string value; 2) string is too large (exceed 8000).
For debugging this, change the destination column to VARCHAR(MAX).
Then load the raw file (do not forget to increase the external column length to 8000 in the Advanced page in flag file connection manager).
if:
1) it is loaded successfully, query the table where ISNUMERIC([that numeric column]) =0, if anything returned, that is the bad record that cannot be converted when loading.
2) it is not loaded correctly, try to see if you have any value from that field has more than 8000 characters. (could use C# script if it is impossible to manually check)

SQL SERVER, importing from CSV file. Data conversion error

I am trying to import data from a CSV file into a table.
I am presented by this error:
"Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data
conversion for column "dstSupport" returned status value 2 and status
text "The value could not be converted because of a potential loss of
data."."
However, I do not even need to convert this column, as you see in the image below:
The column is of type bit, and I used DST_BOOL.
This ended up being a parsing error. I had a string with commas within it, and these strings within the commas were being placed in my bit column. I fixed it by changing the delimiter from a comma to a pipe

SSIS package SQL DB to a Excel Spreadsheet destination Unicode Error

I have a DB OLE Source going to an excel destination. I receive the following error
Error at Data Flow [Excel Destination [88]]: Column "X" cannot convert between unicode and non-unicode string data types.
I have added in a data conversion to change string columns to Unicode. this has not resolved the problem. any guidance would be appreciated
Go to your excel destination component --> mapping --> hover your mouse over column in question, you'll see that it is Unicode Str. Something like this :
Hence, you need a data conversion component to add an alias of source column to DT_WSTR Unicode String AND map it in excel destination component.
I replicated your problem and thus providing you solution.
IF this doesn't work, then delete these components and re-add them, as this is will mostly resolve your issue.
Try using a derived column instead of data conversion transformation, use the following expression
If destination is unicode
(DT_WSTR,50)[X]
Else
(DR_STR,50,1252)[X]

Convert from string to int in SSIS

I'm converting a database from one structure into a new structure. The old database is FoxPro and the new one is SQL server. The problem is that some of the data is saved as char data in foxpro but are actually foreign key tables. This means they need to be int types in sql. Problem is When i try to do a data conversion in SSIS from any of the character related types to an integer, I get something along the following error message:
There was an error with the output column "columnName"(24) on output "OLE DB Source Output" (22). The column status returned was : "The value could not be converted because of potential loss of data".
How do i convert from a string or character to an int without getting the potential loss of data error. I hand checked the values and it looks like all of them are small enough to fit into an int data type.
Data source -> Data Conversion Task.
In Data Conversion Task, click Configure Error Output
For Error and Truncation, change it from Fail Component to Redirect Row.
Now you have two paths. Good data will flow out of the DCT with the proper types. The bad data will go down the Red path. Do something with it. Dump to a file, add a data view and inspect, etc.
Values like 34563927342 exceed the max size for integer. You should use Int64 / bigint

Want to use SSIS to get csv file with Null values into SQL Server DB table while preserving Nulls and maintaining floating point casting

Here is an example csv file:
Col1,Col2,Col3,Col4
1.0E+4,2.0E+3,3.1E-2,4.1E+4
NULL,1.0E-2,2.0E+1,3.2E-2
Using SSIS in Visual Studio, I want to get this file from csv format to a SQL Server DB table. I have a Data Flow Task which contains a Flat File Source and an ADO NET Destination. The SQL table has already been created with all columns cast as float. In the Flat File source I cast all columns as (DT_R4). An error is raised when I execute the package. The error is [Flat File Source [21]], data conversion failure for Col1. It is because I have a "Null" in the file. If instead of a Null I have an empty space, the SQL data table contains a "0" rather than a "Null." Is there anything I can put in place of "Null" in the csv file that SQL Server will interpret as Null and won't cause errors for SSIS? Please keep in mind that I actually have 100+ data files, each 500 MB big and each with 600+ columns.
Use a derived column component - Create a DerivedCol1 as
[Col1]=="Null"? NULL(DT_R4):[Col1] and map it to the destination column. Hope this helps.
Did you try
IsNull(col)?" ":col in derived column
If you look at the technical error when you click OK you can see that it needs cast:
"null" == LOWER(myCol) ? (DT_STR, 50, 1252) NULL(DT_STR, 50, 1252) : myCol
It's weird becase NULL(DT_STR,50,1252) should already return a null of that type.