SSIS Choosing Wrong Data Type - ssis

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.

Related

SSIS data conversion (from unicode to ANSI) returned status value 4

I have the following problem:
I have an SSIS package that starts with a query executed at an Oracle DB and I would like to export a Fixed Width flat file with ANSI 1253 Code Page. I get an error:
The data conversion for column [column_name] returned status value 4
and status text "Text was truncated or one or more characters had no
match in the target code page"
The problem has to do with the second part of the message, as the width is ok. I tried to use Data Conversion from Toolbox but it didn't work (probably I didn't use it on the right way). I have only select privileges to the database so I cannot add any sql procedures to remove special characters at the query. Also the idea to load data to a staging table wouldn't be the best choice at my case. Does anyone has any idea on how to convert my data without getting this error?
Thanks a lot in advance
Load data using your Source from Oracle DB and keep the data types they are giving you.
add a derived column and cast your column.
(DT_STR,[Insert Length],1252) [columnName]
if the column is ntext you need to do 2 steps to get to string.
(DT_STR...) (DT_WSTR) Ntextcolumn

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 package writing to CRM 2011 Data type error

We are trying to push a single order in to MS CRM (dev instance) via SSIS package.
Most of the columns coming from source (staging table) are of data type 'DT_STR' and their mapped fields in CRM are of 'DT_WSTR' data type.
I already looked for the solution on this site but in all cases the question is for converting wstr to str. In my case I need to convert str to wstr. when I run the package I get error saying,
Column xxxx cannot convert between unicode and non unicode string data type
I have already tried two solution:
1. Right click on the OLE source and convert datatype to wstr and
2. Using 'Data Conversion'
In both cases the error remains the same. Has anyone else had similar issue?
In OLE DB Source properties don't change data types. If you want you can change in
SELECT statement in OLE DB source.
you can change in 'Data Conversion'
Derived Column element
In Derived Column element code is:
(DT_WSTR, 50)([YourString])
Don't replace column, add new column in Derived column element.
You doing something wrong if you can't convert, you don't give real error message (or picture of your design), real error message is in Output window when you execute the package.

Data Conversion Issue in SSIS package - Text to GUID

I am developing a SSIS package that will open an Excel spreadsheet and import the data into a database table in SQL Server 2008. When I try to convert the Excel column data type: Unicode String [DT_WSTR] to a unique identifier data type: unique identifier [DT_GUID], I get the following error:
"Invalid character value for cast specification"
What do I need to do to resolve the conversion error?
I used a Derived Column Transformation Editor and to wrap the excel column value in squrly brackets {} in order for the SSIS package to properly convert the Unicode String into a GUID.
I want to mention that this will not work with SSIS 2012 in Visual Studio. If you try to do this you get an error on the derived column transformation task. I've tried both of these:
(DT_GUID)[ColumnName]
(DT_GUID)("{" + [ColumnName] + "}")
Both of these will fail.
However, if you simply set to ignore those errors instead of fail. It will work fine. Really spend way too much time trying to get this to work.

Date casting issue in data conversion task

my date format is in this format YYYYMMDD and when I am converting the same with data conversion task I am getting below error:
The data value cannot be converted for reasons other than sign mismatch or Data Overflow.
In my Dataconversion I have select DT_DATE
and in database the column datatype is date.
But the strange thing is that when I am executing my package and doing casting as source SELECT CAST(myDate AS DATE) package is working fine.
It's a common issue. If you use a derived column transformation, you will need to slice it out into the component parts (years, months, days) and then concatenate it back together before casting. That's ugly and time consuming for me.
Instead, assuming this is coming from a flat file, just make it a date on import by setting the type in your connection manager to the date type that will be compatible with your destination. Then on your flat file source, under advanced settings, set FastParse to true for that column. See my answer on Import String Date in Derived column for a pictoral walkthrough of it. Also addressed it on SSIS importing datetime column into SQL Server 2008