SSIS Derived Column (Find String) - sql-server

I am extracting pattern from the 'Notes' column, I am looking for an alpha numeric word (MXPC123456) from the notes and I want to store the output in a new column. So for that I am using a Derived Column and FindString() function.
I am getting error when I run this code using the following expression in Drived Column inside my SSIS package:
(DT_WSTR,255)SUBSTRING(TEXT_LINE1,FINDSTRING(TEXT_LINE1,"MXPC",1),10).
Don't know what I am doing wrong.
Error: 0xC0049067 at Get DC Coms Data, Derived Column [67]: An error occurred while evaluating the function.
Error: 0xC0209029 at Get DC Coms Data, Derived Column [67]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "component "Derived Column" (67)" failed because error code 0xC0049067 occurred, and the error row disposition on "output column "CKT_MX" (91)" 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.
Error: 0xC0047022 at Get DC Coms Data, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Derived Column" (67) failed with error code 0xC0209029 while processing input "Derived Column Input" (68). 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.
Could you please help?
Regards
Prab

There are 2 things that may cause this error:
TEXT_LINE1 doesn't contains "MXPC" string , so FINDSTRING(TEXT_LINE1,"MXPC",1) will return 0 and the SUBSTRING function will throw an exception
TEXT_LINE1 contains "MXPC" string but there is no 10 characters after the FINDSTRING returned value
TEXT_LINE1 IS NULL
so you can add some validation to this expression
ISNULL([TEXT_LINE1]) == TRUE ? "" : (FINDSTRING([TEXT_LINE1],"MXPC",1) == 0 ? "" :
(LEN([TEXT_LINE1]) >= FINDSTRING([TEXT_LINE1],"MXPC",1) + 9 ? SUBSTRING([TEXT_LINE1],FINDSTRING([TEXT_LINE1],"MXPC",1),10) : ""))

Related

Error at Data Conversion Transformation when Trying to Convert String from Excel Source to DB_TIMEZONEOFFSET to SQL Server Destination

Been several years since I had to write an SSIS package and struggling with converting a datetimezone string from Excel to Data Conversion transformation converting to DB_TIMEZONEOFFSET to a SQL Server Destination.
The following is the Timestamp in all 7 rows of Excel source:
The date column from the Excel source is a Unicode String [DT_WSTR] as seen below:
The SQL Server destination field is setup as DATETIMEOFFSET(7) as seen below:
I am receiving the following errors on the Data Conversion transformation when run the data flow:
[Data Conversion 2] Error: Data conversion failed while converting
column "Column1.createdAt" (82) to column "Copy of Column1.createdAt"
(38). 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[Copy of
Column1.createdAt]" failed because error code 0xC020907F occurred, and
the error row disposition on "Data Conversion.Outputs[Data Conversion
Output].Columns[Copy of Column1.createdAt]" 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.
It is also important to note that I did also try to use a Derived Column transformation before the Data Conversion transformation as well to cast as DATETIMEOFFSET(7) to match that of SQL Server destination and received errors there as well similar to above.
Been fighting this for a while now and any extra eyes will help.
Thanks.
ssis cannot do the conversion if there are T and Z letters in the field. Use the REPLACE command to replace the letter T with space and the letter Z without characters. Like This : (DT_DBTIMESTAMPOFFSET,7)REPLACE(REPLACE(createdAt,"T"," "),"Z","")

data conversion issue while executing a ssis package

Executing my package and i am seeing below error. EMP ID from source (Flat file) is DT_STR(50) and loading it into table:
EMP_ID int not null column
Using data conversion task i am converting it in to four byte signed integer
But Job is failing.
Description: Data conversion failed while converting column "EMP ID"
(105) to column "EMP ID" (25). The conversion returned status value 2
and status text "The value could not be converted because of a
potential loss of data.". End Error Error: 2019-09-16 11:37:28.53
Code: 0xC0209029 Source: Data Flow Task 1 Data Conversion 0 - 0
[2] Description: SSIS Error Code
DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Data Conversion
.Outputs[Data Conversion Output].Columns[EMP ID]" failed because error
code 0xC020907F occurred, and the error row disposition on "Data
Conversion 0 - 0.Outputs[Data Conversion Output].Columns[EMP ID]"
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. End Error Error:
2019-09-16 11:37:28.53 Code: 0xC0047022 Source: Data Flow Task
SSIS.Pipeline Description: 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. End Error DTExec: The package
execution returned DTSER_FAILURE (1). Started: 11:37:27 AM
Finished: 11:37:28 AM Elapsed: 0.797 seconds. The package execution
failed. The step failed.
The main error is:
The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data
It looks like that the source column contains values that cannot be converted to integer, you can configure the error output to redirect bad rows to a flat file destination in order to check the values that are causing this error.

SSIS VS2012 convert flat file Text to Boolean

I am trying to take data from a CSV and import the records into my database. I have an SSIS package that reads in the flat file, passes it through a data conversion and then sends it to the database.
The problem I am having is the field that has "True" "False" or blank needs to be converted to a Boolean. This package worked in the past but we have upgraded from SQL 2008 to SQL 2014 and taken the package from VS2008 to VS2012.
Error:
Error: 2015-09-15 23:00:03.23
Code: 0xC02020C5
Source: Data Flow Task 1 Data Conversion 0 - 0 [2]
Description: Data conversion failed while converting column "aginactive"
(192) to column "aginactive" (62). The conversion returned
status value 2 and status text "The value could not be
converted because of a potential loss of data.".
End Error
Error: 2015-09-15 23:00:03.23
Code: 0xC0209029
Source: Data Flow Task 1 Data Conversion 0 - 0 [2]
Description: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The
"Data Conversion 0 - 0.Outputs[Data Conversion Output].
Columns[aginactive]" failed because error code 0xC020907F
occurred, and the error row disposition on "Data Conversion
0 - 0.Outputs[Data Conversion Output].Columns[aginactive]"
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.
End Error
Error: 2015-09-15 23:00:03.23
Code: 0xC0047022
Source: Data Flow Task 1 SSIS.Pipeline
Description: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput
method on component "Data Conversion 0 - 0" (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.
End Error
Any thoughts?
Instead of the Data Conversion Transformation, use a Derived Column Transformation. Create a new Boolean column with an Inline IF, so that if the input value is "True" it outputs 1, else 0. Then use the new column in your destination.

Data conversion failed -"The value could not be converted because of a potential loss of data."

I have a simple data flow where I read data out of a table, do some data conversions, and load it into another table:
However when I run the package I get the following errors:
Error: 0xC02020C5 at Atish to CRM, Data Conversion [142]: Data conversion failed while converting column "CAMPAIGNID" (27) to column "Copy of CAMPAIGNID" (206). The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
Error: 0xC0209029 at Atish to CRM, Data Conversion [142]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Data Conversion.Outputs[Data Conversion Output].Columns[Copy of CAMPAIGNID]" failed because error code 0xC020907F occurred, and the error row disposition on "Data Conversion.Outputs[Data Conversion Output].Columns[Copy of CAMPAIGNID]" 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.
Error: 0xC0047022 at Atish to CRM, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Data Conversion" (142) failed with error code 0xC0209029 while processing input "Data Conversion Input" (143). 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.
My mappings:
Lastly since the error seems to be complaining about 'CAMPAIGNID', the datatype of it on the destination table is uniqueidentifier. I honestly don't know what I'm missing here.
You are converting CAMPAIGNNAME to uniqueidentifier and CAMPAIGNID to string[DT_STR]. However your description seems to indicate that CAMPAIGNID must be uniqueidentifier
Also as per the error, your settings seem to indicate Failure on error. If you are sure that the conversion is correct and there will be no truncation, then you can change that property to Ignore on error. Alternately, you can use Error output and redirect it to another destination and inspect the results.
Also it is unclear why you are converting all the columns. Adding datatypes of your source and destination columns might add more clarity.

SSIS - Derived Column

I am having an issue with using the Derived Column Transformation Editor and was wondering if anyone on here could help me out.
I have a column called WorkitemNumber that holds information like INC0000001234
I want to change the WorkitemNumber to a more unique number to prevent overlapping entries in between months. So I came up with this...
I have a Derived Column:
Derived Column Name: ConvertID
Derived Column: <add as new column>
Expression: REPLACE(WorkitemNumber,"INC","") + "913"
Data Type: Unicode string [DT_WSTR]
Length: 258
The expression above changes INC0000001234 to 0000001234913. What I would like to do is cut out all of the extra 0s, but I want to refrain from using LTRIM because it will break once the incident report numbers go to the next set of thousands.
I am pretty new with using SSIS and it would be really helpful if someone would be able to tell me how I would go about getting rid of the extra 0s on the end regardless of the amount of 0s in front of the incident number.
I would want the final output to be 1234913 recardless if the incident number was INC0000001234 or INC001234.
EDIT
I was able to drop the 0s but I am getting the following error and the information is not being written into my other tables...
[SQL03 [459]] Error: SSIS Error Code DTS_E_OLEDBERROR.
An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0"
Hresult: 0x80004005 Description: "Invalid character value for cast specification".
[SQL03 [459]]
Error: There was an error with input column "ConvertIncidentID" (1015)
on input "OLE DB Destination Input" (472).
The column status returned was: "Conversion failed because the data value
overflowed the specified type.".
[SQL03 [459]]
Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.
The "input "OLE DB Destination Input" (472)"
failed because error code 0xC020907A occurred, and the error row disposition on
"input "OLE DB Destination Input" (472)"
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 "SQL03" (459)
failed with error code 0xC0209029 while processing input "OLE DB Destination Input"
(472). 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.
If you're trying to strip the leading zeros, I would go with this approach
This expression removes the INC from your string
REPLACE(WorkitemNumber,"INC","")
Once INC is removed, you can cast to a numeric type to drop the leading zeros and then back to a string to allow you to do concatenation or whatever else you may need to do
(DT_WSTR,10)((DT_I8)REPLACE(WorkitemNumber,"INC",""))
Personally, I find it more user friendly to chain Derived Columns together so that if it breaks, I can spot the error more easily than something like the above. In your case, I used the original replace to generate a column and then use
(DT_WSTR,10)((DT_I8)WorkItemNoINC)
in my second Derived column
Edit
Taking another bite at the apple
OLE_SRC Query
I have defined the following source query
SELECT
'INC0000001234' AS WorkitemNumber
, CAST(MONTH(D.foo) AS varchar(2)) + RIGHT('0' + CAST(DAY(D.foo) AS varchar(2)), 2) AS fudge
FROM
(
-- Generate a year's worth of dates
SELECT
DATEADD(d, NUMS.n, '2012-12-31') AS SourceDate
FROM
(
SELECT TOP 366 ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n
FROM sys.all_columns AS SC
) NUMS
) D(foo);
This query generates 366 rows of data. A constant column named WorkItemNumber and one called fudge that will be all the possible month + day combinations. I left pad the number with a 0 so that a value of 121 is clearly January 21 and not December 1.
DER Drop INC
Here I create a new column called WorkItemNoINC and use the expression
REPLACE(WorkitemNumber,"INC","")
The result of this operation is that the text INC is removed from the source column and an empty string substituted in its stead.
DER WorkItemConcat
In this step, I concatenate the WorkItemNoINC column with our fudge value generated from the query. String + String yields string named WorkItemConcate (because I didn't proofread)
WorkItemNoINC + fudge
DER Strip leading zeros
In this operation, I will cast the value of WorkItemConcate to a bigint and back to string to strip the leading zeros.
(DT_WSTR,10)((DT_I8)WorkItemConcate)
Run
I added a data viewer after the last transformation and you can see that for all the possible values of day and month in a year, these expressions do not present a problem.
Making it fail
If I update my source query to use a NULL for WorkItemNumber, this package will not fail as you are experiencing.
If I change the casing in WorkItemNumber to inc, then I can generate this error.
Error: 0xC0049064 at DFT Whatevs, DER Strip leading zeros [18]: An error occurred while attempting to perform a type cast.
Error: 0xC0209029 at DFT Whatevs, DER Strip leading zeros [18]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "DER Strip leading zeros" failed because error code 0xC0049064 occurred, and the error row disposition on "DER Strip leading zeros.Outputs[Derived Column Output].Columns[Derived Column 1]" 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.
Error: 0xC0047022 at DFT Whatevs, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "DER Strip leading zeros" (18) failed with error code 0xC0209029 while processing input "Derived Column Input" (19). 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.
Similar but not the same as you. I don't have a 2008 instance handy to test against but try breaking your operations out across multiple derived columns transformations and add data viewers as needed.

Resources