DataStage Transformer stage how to check if explicit text is in the column's values - datastage

Currently, I am using the Count function inside a Transformer stage in a parallel job to check if the values of 1 Stage Variable (StageVar) contain some explicit value then give another column (Code) some values.
There's so many Code to check in the StageVar but I'll just take the 'D' code for example:
If the StageVar contains 'DEBT' (and only 'DEBT', not any other string like 'DEBTOR' or 'ODEBT', etc) in its value, the Code column for that row will have the 'D' code.
Here's the code that I use in the Code column's derivation:
If Count(StageVar, 'DEBT') > 0 Then 'D' Else SetNull()
It succeeded in giving the code 'D' to which row that the StageVar contains the 'DEBT' string. But the problem is the content of the StageVar is not always having the 'DEBT' string that stands alone.
There're some cases that the StageVar may contain the 'DEBTOR' like 'PAY DEBTOR STATEMENT IN NOVEMBER' or 'ODEBT' like 'PAYMENT ODEBT FOR NOVEMBER', which I'll ignore and not giving the 'D' code for the Code column.
But the above code also giving the 'D' code for them.
Do you guys have any idea how to fix this inside the Transformer stage itself?
Thanks!

Make sure that StageVar has a leading space and a trailing space. For example " NATIONAL DEBT IS OUT OF CONTROL "
You could use Count() function, but Index() is probably more what you want. Also encase your search string in space characters.
If Count(StageVar, " DEBT ") > 0 Then "D" Else SetNull()
If Index(StageVar, " DEBT ", 1) > 0 Then "D" Else SetNull()
Index() stops searching as soon as it finds the first occurrence. Count() must perforce search to the end of StageVar.

Related

Why am I getting an error that I cannot concat two different datatypes even after casting the fields datatype

I have a query in postgresql where I want to append a minus sign to the transactions.amount field when the transaction.type = 2 (which refers to withdrawals). I am trying to concat a minus sign and the transactions.amount field which is an int. I casted the transactions.amount field to a text/varchar but no matter what I still get the error, "PostgreSql Error: case types numeric and text cannot be matched"
Here is the query I am running,
SELECT CAST(CASE WHEN "IsVoided" IS TRUE THEN 0
WHEN "Transactions"."TransactionType" = 2
THEN CONCAT('-', CAST("Transactions"."Amount" AS TEXT))
ELSE "Transactions"."Amount" END AS Text) AS "TransAmount"
FROM "Transactions"
LEFT JOIN "DepositSources"
ON "Transactions"."DepositSourceId" =
"DepositSources"."DepositSourceId"
LEFT JOIN "WithdrawalSources"
ON "Transactions"."WithdrawalSourceId" =
"DepositSources"."DepositSourceId"
WHERE "Transactions"."FundId" = 4
AND "Transactions"."ReconciliationId" = 24
What's very perplexing is when i run the below query it works as expected,
SELECT CONCAT('-', CAST("Transactions"."Amount" AS TEXT)) FROM
"Transactions"
All branches of a CASE expression need to have the same type. In this case, you're stuck with making all branches text, because what follows THEN can only be text. Try this version:
CASE WHEN IsVoided IS TRUE
THEN '0'
WHEN Transactions.TransactionType = 2
THEN CONCAT('-', Transactions.Amount::text)
ELSE Transactions.Amount::text END AS TransAmount
Note that it is unusual to be using the logic you have in a CASE expression. Typically, you would just be checking the values of a single column, not multiple different columns.
Edit:
It appears that your call to CONCAT mainly serves to negative a value. Here is one more simple way to do this:
CASE WHEN IsVoided IS TRUE
THEN 0
WHEN Transactions.TransactionType = 2
THEN -1.0 * Transactions.Amount
ELSE Transactions.Amount END AS TransAmount
In this case, we can make the CASE expression just generate numeric output, which might be really what you are after.

Cast to int instead of decimal?

I have field that has up to 9 comma separated values each of which have a string value and a numeric value separated by colon. After parsing them all some of the values between 0 and 1 are being set to an integer rather than a numeric as cast. The problem is obviously related to data type but I am unsure what is causing it or how to fix it. The problem only exists in the case statement, the split_part function seems to be working perfect.
Things I have tried:
nvl(split_part(one,':',2),0) = COALESCE types text and integer cannot be matched
nvl(split_part(one,':',2)::numeric,0) => Invalid input syntax for type numeric
numerous other cast/convert variations
(CASE WHEN split_part(one,':',2) = '' THEN 0::numeric ELSE split_part(one,':',2)::numeric END)::numeric => runs but get int value of 0
When using the split_part function outside of case statement it does work correctly. However, I need the result to be zero for null values.
split_part(one,':',2) => 0.02068278096187390979 (expected result)
When running the code above I get zero but expect 0.02068278096187390979
Field "one" has the following value 'xyz: 0.02068278096187390979' before the split_part function.
EXAMPLE:
create table test(one varchar);
insert into test values('XYZ: 0.50000000000000000000')
select
one ,split_part(one,':',2) as correct_value_for_those_that_are_not_null ,
case
when split_part(one,':',2) = '' then null
else split_part(one,':',2)::numeric
end::numeric as this_one_is_the_problem
from test
However, I need the result to be zero for null values.
Your example does not deal with NULL values at all, though. Only addressing the empty string ('').
To replace either with 0 reliably, efficiently and without casting issues:
SELECT part1, CASE WHEN part2 <> '' THEN part2::numeric ELSE numeric '0' END AS part2
FROM (
SELECT split_part(one, ':', 1) AS part1
, split_part(one, ':', 2) AS part2
FROM test
) sub;
See:
Best way to check for "empty or null value"
Also note that all SQL CASE branches must agree on a common data type. There have been minor adjustments in the logic that determines the resulting type in the past, so the version of Postgres may play a role in corner cases. Don't recall the details now.
nvl()is not a Postgres function. You probably meant COALESCE. The manual:
This SQL-standard function provides capabilities similar to NVL and IFNULL, which are used in some other database systems.

An access query comparing the time part in a date field with values input in a form

I have an access query with predicates (conditions) on a date/time column called start_time. The condition is on two form fields defined with "Format" as "short time". The problem is that this query does not give correct results.
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm")
BETWEEN [Forms]![CustEventRptForm]![FromHour]
AND [Forms]![CustEventRptForm]![ToHour]
Also tried it using Format([start_time], "short time") BETWEEN ... - did not work either.
Do we need anything in addition to above code to get the correct results?
I have tested with literal values as shown below and I get correct results with that.
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm") BETWEEN '10:00' AND '13:00'
My guess is it's not interpreting the value from the form correctly.
Try adding quotes before and after the values:
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm") Between "" & [Forms]![CustEventRptForm]![FromHour] & ""
And "" & [Forms]![CustEventRptForm]![ToHour] & ""
Don't use string comparisons for date/times.
SELECT event_cust.*
FROM event_cust
WHERE TimeValue([start_time]) >= CDate([Forms]![CustEventRptForm]![FromHour])
AND TimeValue([start_time]) <= CDate([Forms]![CustEventRptForm]![ToHour])

Centura Gupta Team Developer Automation Possibility

Is there a automation tool which can automate the software build on Team Developer (v6.0).
I have tried with multiple automation tools to spy the table object in the application, it identifies it as Gupta ChildTable. But I am not able to retrieve the values from the row.
For example:
1. I have 10 rows in the table(grid) with 12 columns. I need to find the value "AAAAA" contained in first column and select that particular row via Automation.
2. I have 10 rows in the table(grid) with 12 columns. I need to find the value "AAAAA" contained in first column and click on particular cell in that row to input the data via Automation.
Thanks in advance.
Use VisTblFindString . This function ( and many others ) are included into your TD code if include 'VT.apl' in your include libraries .
VisTblFindString will return the Row - so then you simply set context to that row using SalTblSetContext( hWndForm, nRow ) , and then you can refer to the contents of each cell by name to return the value.
Syntax
nRow = VisTblFindString(hWndTable, nStartRow, hWndColumn, sString)
Handle: hWndTable
Number: nStartRow
Number: hWndColumn
String: sString
Description
Locates a string value within a column.
The string must match exactly, but case is ignored. Searching ends when the last row in the table is checked. A SAM_FetchRow message is sent for all rows that have not yet been fetched into the cache.
You can use the pattern matching characters understood by the function SalStrScan. The percent character (%) matches any set of characters. The underscore character ( _ ) matches any single character.
Parameters
hWndTable Table window handle.
nStartRow Row number at which to start the search.
hWndColumn Handle of column to search. Use hWndNULL to search all string columns.
sString String for which to search.
Return Value
Number: The row number if sString is found, or -1 if not found.
Example:
Set nRow = VisTblFindString (twOrders, 0, colDesc, 'AAAAAA')
Call SalTblSetContext( twOrders , nRow )
( Now you can get the value of any cell in nRow by referring to the Column Name )
e.g. Set sCellValue = twOrders.colDesc or Set sCellValue = twOrders.colId etc.
Rows ( or anything what-so-ever in a TableWindow - even the cell borders , backgrounds , lines, row headers etc ) can be treat as an 'Item' or 'Object' by TeamDeveloper . Recommend you use MTbl - it is an invaluable set of add-on functions that make dealing with Tables a breeze. I know of no sites using TableWindows that don't use MTbl. In terms of rows , you can define any row as an Item or Object and manipulate it accordingly. See M!Tbl ( a TableWindows extention ) and specifically fcMTblItem.DefineAsRow( hWndTbl, nRow ).
BTW , you can also use MTbl to completely change the look and feel of your TableWindows , to give them a real modern look.
Very rough napkin code, don't have TD on this computer. Not that you can copy&paste this easily anyway due to the code structure, only line by line.
tbl1 is the name of the table, col1 is the name of the column, substitute to fit your program.
Set nRow = TBL_MinRow
While SalTblFindNextRow( tbl1, nRow, 0, 0 )
Call SalTblSetContext( tbl1, nRow )
If tbl1.col1 = "AAAAA"
Call SalTblSetFocusCell( tbl1, nRow, tbl1.col1, 0, -1 )
Break
This should run through each row, check whether col1 has the chosen value, and then activates edit mode for that cell - provided the column is editable.

Nested if else Condition in Crystal report

I have a .rpt file , with a view datasource . I have four parameter which i use in filtering the selection. I have written my selection formula like below.
if ({?actype} <> "All") OR ({?actype} <> "All") OR ({?collectorname} <> "All") OR ({?batchno}<> "All") Then
(
if {?actype} <> "All" Then
{CollectorPerformance.accountType} = {?actype};
if {?collectorname} <> "All" Then
{CollectorPerformance.realname} = {?collectorname};
if {?batchno} <> "All" Then
{CollectorPerformance.batchno} = {?batchno}
and
{CollectorPerformance.clientid} = {?clientid}
and
Date({CollectorPerformance.paymentdate}) >= Date({?from})
and
Date({CollectorPerformance.paymentdate}) <= Date({?to})
)
My issue with the formula, above is that it does not filter by realname and actType. I understand the reason is because the key word "and" is missing . however, it filters the batchno correctly> please how do i make it filter by the remaining two if's ? any help would appreciated.
A selection formula has to be one long valid boolean statement, which is, I think, what you were already suggesting when you say the "and is missing". So in order to fix the first half, you just need to translate those statements into one simplified boolean statement instead of individual statements (those that end in a ';').
({?actype}="All" or {?actype}={CollectorPerformance.accountType})
and
({?collectorname}="All" or {?collectorname}={CollectorPerformance.realname})
and
({?batchno}="All" or {?batchno}={CollectorPerformance.batchno})
...
For each parameter, a user can either select "All" or enter a specific value to filter by. If "All" is selected, that particular portion of the statement (The part that looks like {?Parameter}="All") will evaluate to True and no filtering will be done. Otherwise, only records matching the entered parameter value will return True.