I am trying to cast a String (DT_WSTR) as a Date Format (DT_DBDATE) in SSIS.
My source is a Excel-File and the input field looks as follows: OCT 04 2020
My Result should have the format 2020-10-04
I use a Derived Column Editor and created this expression:
(DT_DBDATE)(SUBSTRING([BILLING CYCLE DATE],8,4) + "-" + SUBSTRING([BILLING CYCLE DATE],1,3) + "-" + SUBSTRING([BILLING CYCLE DATE],5,2))
The error I get is:
[Derived Column [312]] Error: An error occurred while attempting to perform a type cast.
[Derived Column [312]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "component "Derived Column" (312)" failed because error code 0xC0049064 occurred, and the error row disposition on "input column "BILLING CYCLE DATE" (388)" 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 "Derived Column" (312) failed with error code 0xC0209029 while processing input "Derived Column Input" (313). 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 know that there are several questions that a similar, I also tried a lot of them but nothing helped me so far.
I have no Idea why it is not working as it used to work one month ago. And in other SSIS Packages similar expressions are working fine.
Any answer is appreciated!
I found the solution:
I had to transform the monthname OCT into a number 10.
So tried this solution: Convert month name to month number in SSIS
(SUBSTRING([BILLING CYCLE DATE],1,3) == "OCT" ? "10" : "") + SUBSTRING([BILLING CYCLE DATE],4,3) + SUBSTRING([BILLING CYCLE DATE],7,5)
After that I did the above expression in a seperate Derived Column and it worked very fine!
(DT_DBDATE)(SUBSTRING([BILLING CYCLE DATE],7,4) + "-" + SUBSTRING([BILLING CYCLE DATE],1,2) + "-" + SUBSTRING([BILLING CYCLE DATE],4,2))
You can use a script component transform:
DateTime.ParseExact(Row.stringDate, "MMM dd yyyy", CultureInfo.InvariantCulture);
The inputs are string to convert, format, and culture.
Related
In the SO Invoice report, I add a link from ARTran to FSAppointment. This is done in order to include FSappointment.LongDescr in the report. A request, is to remove the text 'Internal Notes' PLUS all text following the string. I notice a red error message printed in the report output, in the cases where 'Internal Notes' string is not included in LongDescr. I tried several permutations but have not found a resolution.
Here is my formula
=IIf(InStr([FSAppointment.DescriptionAsPlainText],'Internal Notes')>0,
Left( [FSAppointment.DescriptionAsPlainText], InStr([FSAppointment.DescriptionAsPlainText],'Internal Notes') )
,[FSAppointment.DescriptionAsPlainText])
Note that I created a non-bound field DescriptionAsPlainText, in order to apply pretty formatting, for LongDescr field.
Here is the error message:
An error has occurred while the Left(Identifier(FSAppointment.DescriptionAsPlainText), InStr(Identifier(FSAppointment.DescriptionAsPlainText), Const(Internal Notes))) function was being executed:
'Length cannot be less than zero.
Parameter name: length'
I think your code fails if the value of [FSAppointment.DescriptionAsPlainText] is null. Add an IIF([FSAppointment.DescriptionAsPlainText]=null, clause around your existing code to exit in case of null.
In Data Flow task I am trying to replace * with Data Flow component "Derived Column" using the following expression:
REPLACE(Code, "*", " ") - but this simple replace statement will not work, I have also tried to cast "Code" as DT_WSTR, but no help so far. Hopefully someone know how to do it. "Code" value is coming from excel source and data type for it is DT_R8
Error at Data Flow Task [Derived Column 1 [57]]: The function
"REPLACE" does not support the data type "DT_R8" 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.
As a start, I am extremely new at Python.
I am receiving an Excel file where the date field is incomplete. The value displays as "190808" (YYMMDD) instead of "2019-08-08".
Part of my automation attempt is to move the file to a different location, where the file is renamed. I want to use the date field to change the file name to the file description and date (e.g. "Sales figures 201908").
The code I have only works if the date format is
str(df['Bank date'][0].strftime("%Y%m"))
I have tried dateparser with the following:
dateparser.parse(df['Bank date'][0].strftime("%Y.%m"))
The error I am receiving is 'numpy.int64' object has no attribute 'strftime'
Any help will do.
Thanks.
I modified it slightly and built my own date-string using slicing.
vOldDate = str(df['Bank date'][0])
vNewDate = '20' + vOldDate[:2] + '.' + vOldDate[2:4]
Numpy is interpreting the date as an integer. To use dateparser, you need to convert that value into a string first, then parse that string, and then format the result:
dateparser.parse(str(df['Bank date'][0])).strftime("%Y.%m")
Since the input format is expected, you should specify it to ensure you get the right date:
>>> dateparser.parse(str(190808), date_formats=['%y%m%d']).strftime("%Y.%m")
'2019.08'
I'm writing a macro to cycle through a number of different spreadsheets that are in exactly the same format as each other. The source spreadsheets contain data in a table which occasionally contains the #NUM error (thanks to something going wrong in a different model!)
I have managed to account for all other error types, and some interesting formatting rules, using the below with a few other Case statements:
If IsNumeric(resultsarray(q,p) = false then
Select case ResultsArray(q,p)
Case IsError(ResultsArray(q, p))
ResultsArray(q, p) = 0
Case Left(ResultsArray(q, p), 2) = "0 "
ResultsArray(q, p) = 0
Unfortunately #NUM doesn't seem to fall into IsError's purview. Does anyone out there know how I can simply overwrite the error with a zero/0?
Thanks in advance!!
Steph
This #NUM error occurs if the input is not a valid number. On your situation i suggets you to check whether the input is number or not instead of error check. This way you can check #NUM error as well.(Or you can do it both) With IsNumeric(<input data here>) you can do it. So just add one more case (IsNumeric) to your select case.
In my Lotus Notes script, i do have this piece of logic as shown below. This is basically for two SELECT statements, followed by Fetch for each of the SELECT statement separately and the SELECT is for the same DB2 table with a variation in WHERE clause. The error i'm getting is for the second FETCH. The error i'm getting is ---> Field count mismatch error:
count = 0
If (srccon.Execute(selectstatement, fldLst1) = 0) Then
Goto GetNextDoc
End If
count = srccon.Fetch(fldLst1)
If ( count = 0 ) Then
Goto GetNextDoc
End If
The above cursor select and fetch does not give me any error.
The cursor down which is for the same DB2 table with a slight variation
in WHERE clause is causing the error:
count1 = 0
If (srccon.Execute(selectstatement1, fldLst) = 0) Then
Goto GetNextDoc
End If
count1 = srccon.Fetch(fldLst) ---> The error is pointing to this line
and the error is
I would appreciate any help in this regard. I would also thank the gentleman who
did excellent solution for my previous problem for current date minus 30 days.
With much thanks
I suspect it's because when you call Execute, you're reusing the same LCFieldList object from a previous call. Execute and Select statements append their list of result fields to the object you pass them, so you must pass them an empty fieldlist -- one you just created. Otherwise you get a combined fieldlist of all the fields in the result sets of multiple calls to Select or Execute.
You may find the LotusScript chapter of this Redbook useful.