I have a column named Paid_Date in my table that has a kind of improper date value with a colon in between date and the time values (e.g. '04MAY2015:00:00:00').
In order to exclude that colon, I have used an expression
((DT_DBTIMESTAMP)SUBSTRING(PAID_DATE,1,9))
in my Derived Column transformation.
When I try running this, I'm getting the following error.
Expression used in my trasformation: (DT_DBTIMESTAMP)SUBSTRING(PAID_DATE,1,9)
Source column data type : varchar
Source column Value: 04MAY2015:00:00:00
Error: [Derived Column [1613]] Error: An error occurred while attempting to perform a type cast.
Detailed Error:[Derived Column [1613]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.
The "component "Derived Column" (1613)" failed because error code 0xC0049064 occurred,
and the error row disposition on "output column "PaidDate" (1954)" 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.
I have even tried to use the following expression:
(DT_DBTIMESTAMP)((DT_STR,50,1252)SUBSTRING(PAID_DATE,1,9))
Is it not possible to convert a string after a SUBSTRING operation?
Casting a string to a DT_DBDATETIME must use a specific string format:
yyyy-mm-dd hh:mm:ss[.fff]
You'll need to transform the string to the standard format before the cast will work.
Extract the month, use a lookup transformation or nested ternary operators to change it to two digit numeric string, then format the results into a string you can cast into a DT_DBDATETIME.
Related
I am creating a package in SSIS, and want to convert a file with one large column into multiple columns.
I have a table containing several rows with a single column of raw data. The data was copied from a notepad file, and each row contains pipe delimiters to separate each column, but because it is a notepad file, each row is copied as one large column. I want to convert each column per row to multiple columns based on their start/end positions.
I tried using SSIS Derived Column Transformation with the SUBSTRING function, but the Data Type is automatically populated as text stream[DT_TEXT], and I get the following error:
Error at [Derived Column[113]]; The function “SUBSTRING”
does not support the data type “DT_TEXT” for parameter number 1. The
type of the parameter could not be implicitly cast into a compatible
type for the function. To perform this operation, the operand needs
to be explicitly cast with a cast operator.
Error at [Derived Column[113]]; Evaluating function
'SUBSTRING' failed with error code 0xC0047089.
Error at [Derived Column[113]]; Computing the expression
"SUBSTRING[RawData],1,5)" failed with error code 0xC00470C5. The
expression may have errors, such as divide by zero, that cannot be
detected at parse time, or there may be an out-of-memory error.
Error at [Derived Column[113]]; The expression
"SUBSTRING[RawData], 1,5)" on "Derived Column.Outputs[Derived Column
Output].Coluns[Derived Column 1] is not valid
Error at [Derived Column[113]]; Failed to set property
"Expression" on "Derived Column.Outputs[Derived Column
Output].Columns[Derived Column 1]. "
When I review other Derived Column Transformation illustrations utilizing SUBSTRING with a file containing individual columns, I notice the Data Type is shown as DT_WSTR.
Do I need to convert to this Data Type? If so, how do I explicitly cast DT_TEXT data types to DT_WSTR with a cast operator in SSIS Derived Column Transformation?
Otherwise, how else could I handle this conversion?
Derived Column Name: EmployerNo
Derived Column: Replace 'RawData'
Expression: SUBSTRING( [RawData], 1, 5 )
Data Type: text stream[DT_TEXT]
I expect the RawData column to be split up (converted) into 8 different columns based on their start and end positions.
Refering to SUBSTRING (SSIS Expression) documentation:
Returns the part of a character expression that starts at the specified position and has the specified length.
You have to convert DT_TEXT column to DT_STR/DT_WSTR before using Substring() function, you can do this using a Script Component, you can use a similar function:
string BlobColumnToString(BlobColumn blobColumn)
{
if (blobColumn.IsNull)
return string.Empty;
var blobLength = Convert.ToInt32(blobColumn.Length);
var blobData = blobColumn.GetBlobData(0, blobLength);
var stringData = Encoding.Unicode.GetString(blobData);
return stringData;
}
Or if the DT_TEXT length doesn't exceed the DT_STR length limit try using the following SSIS expression:
SUBSTRING( (DT_STR,1252,4000)[RawData], 1, 5 )
[Data Conversion [2]] Error: "Failed to convert data when converting LONGITUDE column (103) to" LONGITUDE copy "column (39). This conversion returned the status value 2 and the status text "The value could not be converted due to a potential loss of data. ".
"
[Data Conversion [2]] Error: "SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Data conversion.Output [Data conversion output] .Columns [Copy of LONGITUDE]" object failed due to error code 0xC020907F. Additionally, the error line layout on "Data Conversion. Output [Data Output Data] .Columns [LONGITUDE Copy]" specifies a failure on the error. An error occurred on the specified object of the specified component. Error messages can be sent beforehand with information indicating the reason for the failure.
"
How can I correct it . I have tried changing data types and matching them .
I have checked my EXCEL file for syntax error ... nothing
Are you using Data Conversion transformation? If so, open it, and check the type of Copy of Longitude, compare that with source. Those two data type are not compatible. You could try to convert it to double.
If it is EXCEL destination, you need to convert it to DT_WSTR
you need to double all sizes in "data conversion" ,
first go to "source destination" and mark all nvarchar column
second go "data conversion" go to these columns and make it double size from length
Note : a data conversion by default make every column datatype 50
First of all, when the column isn't NULL, it is successfully able to do the conversion. The destination DB field accepts null values.
In my Data Conversion step I have set the Input Column's DataType to numeric[DT_Numeric], Precision 18, and Scale 2.
I have two rows in my CSV, the first row does not contain any NULLS.. and if I execute that it's a success. However when I add a 2nd row with a NULL value in that column it fails and I get these errors:
[Data Conversion [2]] Error: Data conversion failed while converting column "Column 24" (138) to column "DbColumn24" (22). The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
[Data Conversion [2]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Data Conversion.Outputs[Data Conversion Output].Columns[DbColumn24]" failed because error code 0xC020907F occurred, and the error row disposition on "Data Conversion.Outputs[Data Conversion Output].Columns[DbColumn24]" 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.
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Data Conversion" (2) failed with error code 0xC0209029 while processing input "Data Conversion Input" (3). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
I do not think I need a Derived Column step before data conversion step to handle any nulls because the DB column accepts nulls.
Since your source is a CSV, I doubt that you actually have any NULL values in your source at all. More likely you have empty string values, which are not the same as NULL, and empty strings cannot be implicitly converted to Decimal. You will probably have to explicitly convert the empty strings to NULL in an expression.
The work around would be
1) First convert the column to varchar/nvarchar
2) Use derived column to convert to Decimal
3) Map the converted column to destination
I'm working on importing a CSV into my DB. The data should work, it's data from another application that we used to get through a dblink that we now have to get from CSV thanks to an upgrade.
Dates look like this: 4/30/2001
I tried to do a simple import like I do with numbers and strings, and got an error, so I did a derived column.
The derived column works on the dates that are not null (formula is (DT_DATE)DTE)
The derived column however failed on dates that can contain nulls. I even tried to update the formula to (ISNULL(EDTE) ? NULL(DT_DATE) : (DT_DATE)EDTE). No success, I still get the error:
[Flat File Source - O1 [6743]] Error: Data conversion failed. The data conversion for column
"EDTE" returned status value 2 and status text "The value could not be converted because of a
potential loss of data.".
Originally, in my flat file source, the dates were set to type date, and I got an error before it even got to the derived column. I've changed that to String, and it makes it to derived column, but both boxes are red. Here's the error:
[Derived Column 1 [17270]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.
The "component "Derived Column 1" (17270)" failed because error code 0xC0049063 occurred,
and the error row disposition on "input column "EDTE" (17809)" 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.
Has anyone seen this? Am I importing my data in wrong?
I found the solution.
I import the date as a String. Then using derived column, I use this formula to convert it:
RTRIM([T-DTE]) == "" ? NULL(DT_DATE) : (DT_DATE)[T-DTE]
I have an SSIS package I am using to load a Fixed Width flat file. I have put in all the column lengths and have two packages against similar files working correctly. The third however keeps throwing the following error:
[Source 1 [16860]] Error: Data conversion failed. The data conversion for column "Line Number"
returned status value 2 and status text "The value could not be converted because of a
potential loss of data.".
[Source 1 [16860]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.
The "output column "Line Number" (16957)" failed because error code 0xC0209084
occurred, and the error row disposition on "output column "Line Number" (16957)"
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.
After doing some testing this happens for any column I have the is using the DT_I4 Data Type and has a blank in the column. I was going to try using a derived column, but this seems to fail for some of the columns even if I change them to a string data type to handle the blank as a NULL and then do a conversion to an INT later in the data flow.
In the source and the destination task I have the Retain NULL values checkbox ticked however this hasn't changed anything.
Any suggestions on handling this error where INT seems to fail at converting a blank to a NULL?
DT_I4 maps to a four byte signed integer in SSIS.
You were on the right track with your derived column. You just need to add the right expression.
You can try this expression:
ISNULL([Line Number]) ? "0":[Line Number]
This link may also be of use - see the postcode column in the example
http://www.bidn.com/blogs/DonnyJohns/ssas/1919/handling-null-or-implied-null-values-in-an-ssis-derived-column
I ended up using the approach from this blog post:
http://www.proactivespeaks.com/2012/04/02/ssis-transform-all-string-columns-in-a-data-flow-stream/
to handle all of the null and blank columns via a script task and data conversion.