Convert ODBC DB2 source to Flat File error in SSIS - ssis

I have ODBC DB2 query to get data from database and data type of column only contain varchar(x), date, and int.
However, I'd like to keep them in flat file destination, but isn't able to use UTF-8 encoding. SSIS keeps informing error message below:
[Flat File Destination si_ce_f_hotel_capacity_snapshot_weekly [2]]
Error: Data conversion failed. The data conversion for column
"SOURCE_MARKET_CODE" returned status value 2 and status text "The
value could not be converted because of a potential loss of data.".
This column has varchar(2) datatype from source. And I specify this datatype in ssis flat file structure as DT_WSTR (2).
However, when I change file format to Unicode, everything works just fine.
How do I get this work in UTF-8 ??
Thanks a lot for your answer.

varchar -> DT_STR
Nvarchar -> DT_WST
You should specify the datatype in ssis flat file structure as DT_STR or use the ssis data conversion transformation tool

You need to do a data convertion in the middle of your data flow. This can be done by using a Derived Column or Data Convertion Data Flow Transformation.

Related

SSIS Choosing Wrong Data Type

I've created a table in SQL Server 2016 with this definition:
CREATE TABLE Stage.Test (f1 DATE NULL);
INSERT INTO Stage.Test (f1) VALUES ('1/1/2000');
Notice the f1 column uses the DATE data type.
Then I created a data flow task in SQL Server Data Tools (VS 2019) to load data from that table. I created an OLEDB Source Component and set the source table to Stage.Test. But when I examine the data type of the "f1" column (in both the 'External Column' and 'Output Column' columns), it says it's a Unicode string:
Why is it choosing a Unicode string instead of DT_DATE?
I haven't seen this exact example when it comes to date fields but SSIS converts data automatically when it has detected the field to be of a certain type. Perhaps it's the '/' in your date field that does it. We do not use this date format over in these parts of the world so I've never had the problem. You can especially see this when you import excel files with SSIS. I usually have this problem with strings where unicode strings can sometimes become non-unicode strings.
A way to fix could be to:
edit the sql query to explicitly cast the field as date
add a conversion step in the data flow after the source (like a derived column getting the parts of the string in the right order)
try to change the output datatype by right clicking on the source in the data flow and using the advanced editor and then edit the output column datatype:
SSIS Source Advanced Editor Output
I'm not sure if that 3 would work with this date format issue as I do not have experience with the format myself but it is working fine for my unicode/non-unicode problem.

How to convert binary data to text, and back again

In SSIS, I'm starting with a SQL Source (a table). It has 3 columns, including a varbinary column ("FileBlob") that comes from a filestream (this shows up as type DT_IMAGE in SSIS).
In the first data flow component, I convert the varbinary column to DT_TEXT, and output the result to a flat file. This works.
In the next step, I read in the flat file I just created, attempting to convert the DT_TEXT column back to DT_IMAGE.
I get this error:
The conversion returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.
I'm assuming there's a way to do a round-trip conversion of the binary data to text, and then back to binary. Just not sure what I'm missing. Thanks.

0 getting truncated in DT_WSTR to DT_STR conversion

I am new to SSIS and facing below issue.
Records are being exported from sql server table to flat text file in SSIS.
In table,the column "ABC" is nvarchar(32) not null and it has one of the value 016
In the SSIS mapping from table to Flat file is: DT_WSTR(32) to DT_STR(50)
After export, 016 is exported as 16 in text file.
Can you please suggest why the 0 gets truncated and how to fix it?
Check the datatypes in the Data Flow Path -> Metadata if you changed the source and or destination datatype.
SSIS doesn't always adjust the Data Flow Path Metadata when changing the source or destination datatypes.
Make sure the Data type is set to DT_STR instead of INT (INT will remove leading 0's)
The only way to fix this is to rebuild the Data Flow Path (as far as i know)
I recently had the same issue.

SSIS XML Source String DataType Length Error

I've a XML Source column "Comments" and data type is UniCode WSTR but in the source [UI] its capturing more than 4000 characters so SSIS ETL failed to load in destination table as the error shows "truncation of data length" & Destination column DataType is nVarchar(Max).
Please suggest me how to load the data into destination.
You could declare this column as an NTEXT. However, beware of two downsides of such step:
You have to check this definition every time you update XML datasource Yes, every time, because SSIS likes to reset string XML elements to its default - nvarchar(50).
Using NTEXT column has a negative performance impact, for details see https://stackoverflow.com/a/28507399

SSIS - CSV to SQL Server Data Import Error

I'm trying and playing around a CSV file to import data into the SQL Server table using SSIS.
The package is simple with File Source Task and SQL Server Destination.
The CSV file has 2 fields Transaction_Date and Account_Created. The dates in these fields are the format of 1/2/2009 6:00:00 AM. I am seeing the below error message:
"Error: An exception has occurred during data insertion, the message returned from the provider is: The given value of type String from the data source cannot be converted to type datetime of the specified target column."
Steps I tried below:
I tried using various other destination transformations.
I tried playing around the Data Types inside the Flatfile Connection Managers.
I tried using the Data Conversion Transformations between the Source Task and SQL Server Destination.
When I tried to load the data by providing connection only to Transaction_Date it works. However, when I tried to load by providing connection only to Account_Created it fails.
I am sure I'm missing something silly. Please help.
Regards,
KK
I tired a different method to build the package from start using the Wizard. I used the actual CSV file which had many other columns like Price, Product_name and so on. When I tried to execute the package I see a different error message as below:
"[Destination for AdventureWorks [58]] Error: There was an error with input column "Price" (91) on input "OLE DB Destination Input" (71). The column status returned was: "The value could not be converted because of a potential loss of data.".
"
When I tried a CSV file with only 2 date fields it worked excellent.
I am really puzzled now and thinking this is some kind of data type issues which I am not getting it correct. Can some one pls shred some light into this problem?
Regards,
KK
To load the first two fields (Transaction_Date, Account_Created), you need a DataFlow Task that contains:
Flatfile Source
Derived Column (create two columns to Replace 'Transaction_Date' and 'Account_Created' with formula below)
SQL Server Destination
Notes:
Date format like '1/2/2009 6:00:00 AM' is not parsed by SSIS, make sure the Flatfile Connection Manager treats the fields as Strings (length > 22)
In Derived Column, you can parse '01/02/2009' with this formula:
(DT_DBDATE)(SUBSTRING([Column 2],7,4) + "-" + SUBSTRING([Column 2],4,2) + "-" + SUBSTRING([Column 2],1,2))
The current date format that you have in the file '1/2/2009' makes the conversion very tricky due to the lack of advanced datetime parsing functions of SSIS. Depending on the day and month you will have to subtract from a variable length string, therefore you will have to combine SUBSTRING with FINDSTRING to determine the position of the separator '/'
Good luck