Data flow task fails at source because of datetime conversion? SSIS 2008 - sql-server

Ive seen this type of error before (eg truncation) with strings before but not with datetime fields.
Have a Data flow task that seems to fail at the source. The OLEDB data source is a call to a procedure and among the columns of the resultset is a datetime field GAPPOSTDT. The return value is a datetime and the procedure returns just fine with the expected results. Not so when I run this through the data flow task. Looking at the advanced properties of the oledb source, I see the type for this field set to database timestamp [DT_DBTIMESTAMP] which seems right.
What could be causing this field not to get mapped?
Ive tried simply deleting the dataflow task and recreating it. Same issue.
See error message below.
Error: 0xC020901C at Data Flow Task, OLE DB Source [1]: There was an
error with output column "GAPOSTDT" (61) on output "OLE DB Source
Output" (11). The column status returned was: "The value could not be
converted because of a potential loss of data.". Error: 0xC0209029 at
Data Flow Task, OLE DB Source [1]: SSIS Error Code
DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "output column "GAPOSTDT"
(61)" failed because error code 0xC0209072 occurred, and the error row
disposition on "output column "GAPOSTDT" (61)" specifies failure on
error. An error occurred on the specified object of the specified
component. There may be error messages posted before this with more
information about the failure.
[UPDATE #1]
SSIS 2008
So I changed the procedure output to return varchar(10) instead of datetime. The OLEDB Source in the dataflow now errors with the following
Error: 0xC020901C at Data Flow Task, OLE DB Source [1]: There was an error with output column "GAPOSTDT" (61) on output "OLE DB Source Output" (11). The column status returned was: "Text was truncated or one or more characters had no match in the target code page.".
Error: 0xC020902A at Data Flow Task, OLE DB Source [1]: The "output column "GAPOSTDT" (61)" failed because truncation occurred, and the truncation row disposition on "output column "GAPOSTDT" (61)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
Im now suspecting some "goofy" characters in the data. The collation being used in the source system is SQL_Latin1_General_CP1_CI_AS
[UPDATE #2]
Ok, I think I may have found the issue. In my procedure I have a "dummy" result because my procedure uses temp tables and this is one "work around" with SSIS (see other topics on this). My final result and the dummy result had their columns in the wrong order. So this put data into the wrong columns. I noticed this when I put on a data viewer. After it popped up, I noticed data into the wrong columns. Strange I thought, then after reviewing my procedure, I found the culprit.

There are always problems with datetime fields... ;)
Try to convert this field to string in the query on the source and then apply changes needed with Derived Column Transformation. Where I live we use date format dd.mm.yyyy, but I'm getting at least 3 other different formats of date...
Maybe this is not the best answer but it's worth to try... it suits me well... :)

That is because the data type of input column does not match the destination column well. You mentioned that you have seen that before fot the varchar column, that is because the size(data length) of input record for that column is smaller than the destination, if input is varchar(30), destination is varchar(20), that will cause this issue. Check your datatype, I am guessing there may have some conflicts when you are trying to do with datetime and datetime2, or datetimeoffset
for example:
input varchar(30) destination varchar(30) perfectly match
input varchar(20) destination varchar(30) fine but a warning
input varchar(30) destination varchar(20) if actual is smaller than 20, that is fine, but if bigger than 20, cause error

Related

SSIS ERROR "Conversion failed because the data value overflowed the specified type"

I'm using ssis to parse file txt into sql server. I use script task to convert a string example "20190523100520" (type :yyyy-MM-dd HH:mm:ss) to datetime (it's data type in table sql ).
But I get the error:
[OLE DB Destination [68]] Error: "There was an error with OLE DB
Destination.Inputs[OLE DB Destination Input].Columns[NewEffectiveTS_NXX_X] on
OLE DB Destination.Inputs[OLE DB Destination Input]. The column status
returned was: "Conversion failed because the data value overflowed the specified type.
In script task, tag inputs and outputs, i use database timestamp [DT_DBTIMESTAMP] type for Columns [NewEffectiveTS_NXX_X]
Everyone help me. Thank you so much!
To convert this value to datetime datatype inside the script you can use DateTime.ParseExact() function:
DateTime.ParseExact([Column],"yyyyMMddHHmmss",System.Globalization.CultureInfo.InvariantCulture)
Because the string value 20190523100520 cannot be implicitly converted to datetime by mapping a column of type string to another of type datetime.
Did you try to redirect the error output to a flat file and check if the rows contains wrong data in the datetime field.If you cant find any problem try to put the string in a valid format by inserting "/"," " and ":" for example your string "20190523100520" will become "2019/05/23 10:05:20"

Insert a datetime value with SSIS to an datetime column in a table on a IBM AS/400 library/system

I have the following problem.
I want make a SSIS flow that inserts values from a table in a MS SQL server database to a table in a AS/400 library.
This works for all the values but the datetime2 value. I tried to insert a datetime2 value and a varchar value in the datetime2 format. Both ways did not work.
It gives the following error:
[TABLENAME [11566]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E21.
An OLE DB record is available. Source: "IBMDA400 Command" Hresult: 0x80004005 Description: "CWBZZ5014 Value of parameter COLUMNNAME could not be converted to the host data type.".
An OLE DB record is available. Source: "IBMDA400 Command" Hresult: 0x80004005 Description: "CWBZZ5014 Value of parameter COLUMNNAME could not be converted to the host data type.".
[TABLENAME [11566]] Error: There was an error with input column "COLUMNAME" (12245) on input "OLE DB Destination Input" (11579). The column status returned was: "The value could not be converted because of a potential loss of data.".
Does someone knows how to get this done?
I assume conversion in sql scripting could be better way of mapping destination column in IBM , try this.
CONVERT(TIMESTAMP, #DateTimeVariable ) or
use derived column expression and there by use data conversion.
I would like to try db_timestamp
Data Conversion

How to add null value if a column doesn't exist

I have a package in my ETL that loops through 4 different databases, each with a copy of the same table. I found out that one of the four tables has one extra column named MTFvalue_Permit thus giving me the below error. My fact and staging tables, however, do include this column.
I was hoping ssis would just insert a null value if the column didn't exist. How can I add a null value into my Data Warehouse tables for the other three tables in which this column doesn't exist?
Error:
[Source DB IBS [1]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80040E14 Description: "Statement(s) could not be prepared.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80040E14 Description: "Invalid column name 'MTFvalue_Permit'.".
Edit: I'm thinking about using a case statement like this for the query but I'm getting a different error.
SELECT
[blahblahblah] ,
[blahblahblah] ,
[blahblahblah] ,
[blahblahblah] ,
[blahblahblah] ,
CASE WHEN COL_LENGTH('wmManifests', 'MTFvalue_Permit') IS NOT NULL
THEN [MTFvalue_Permit]
ELSE NULL
END AS 'MTFvalue_Permit'
FROM dbo.wmManifests
Invalid column name 'MTFvalue_Permit'.
I don't think that you can do it using expressions.
You can do this workaround.
Add a Script task that list columns from the table
Build the Select query dynamically:
If the column is not found pass NULL instead of the column name and give an alias (same as column name)
save this query string into a SSIS variable and use it as a source
You can also create a stored procedure that generate the query string. Execute it from a sql task and store the query string into ssis variable
Perhaps I am not understanding your question, but it seams like you are approaching this problem backwards. You cannot insert data into columns that do not exist. Is there a reason this column exists in only one out of four versions of this table? And does this column have a default value that you can leverage?
I would continue inserting to the set of columns that are common among all tables and allow the tables with columns that do not exist in every one of the tables in the set to use the default value for that column.

How to make SSIS truncate numeric field in Flat File Destination

I'd like some advice about handling truncation issues in SSIS. I have a column Col1 which is MONEY in a table. I'd like to output that to a text file (fixed width, ragged right). In the output file, the column which holds Col1 must only be 8 characters wide.
In the OLEDB Data Source, Col1 is specified as:
currency [DT_CY] in both the External Columns and Output Columns tab.
In the Flat File Connection Manager's Advanced tab, Col1 is specified as:
currency [DT_CY], with InputColumnWidth set to 8.
If I populate Col1 with 123456789.00 and execute the task, the OLEDB source succeeds and passes rows to the destination, but the task fails with :
Error: 0xC02020A1 at DFT_Test, FFDEST_Test [3955]: Data conversion
failed. The data conversion for column "Col1" returned status value 4
and status text "Text was truncated or one or more characters had no
match in the target code page.". Error: 0xC02020A0 at DFT_Test,
FFDEST_Test [3955]: Cannot copy or convert flat file data for column
"Col1".
I want to avoid these truncation errors. In the Error Output of the source, I change the Truncation property for Col1 from Fail Component to Ignore Failure. I would have expected that would resolve the issue, but executing the task still gives the same error.
Can someone give some guidance about how to make SSIS simply truncate the column to 8 charactes?
Use a Derived Column task to create a column that is an 8-character string and populate it from the money column. Then in the Destination component, map the Derived Column to the Col1 Destination instead of the original column.
Or, even better, in your source component, use a SQL query that converts your money column to a varchar(8) or char(8) column.

SSIS: Convert between Unicode and Non-Unicode Strings

Setup
I have a data flow task with:
An OLE DB Source selecting all data from a database table (SQL Native)
An OLE DB Destination of an Access 2003 File template (MS Jet 4.0)
So Essentially I am selecting a table and inserting it into a .mdb file.
Problem
I have the error:
column [X] cannot convert between unicode and non-unicode string data types
However If I add a 'Data Conversion Step' to convert all columns of type DT_STR to DT_WSTR, that error message goes away however I get the error message:
[DTS.Pipeline] Error: "component "OLE DB Source" (6289)" failed validation and returned validation status "VS_NEEDSNEWMETADATA".
Iv'e been Googling this problem for a while and still can't fix it.
Any ideas?
Instead of
Select * from tblName
use
Select col1, col2, col3, etc from tblName
The reason I found is, when you use different database, they might have one or two column that cause issue as it's not mapped. So when you use table query, be specific regarding column name.

Resources