Wanting to create a new If Else statement that categorizes by two conditions from different columns. The first one is IsAdult and some of the values have 'adult' in them which is why I used contains; same goes for 'clipped' under the ISCLIPPED column.
I know this may be a syntax error.
if (ISADULT contains 'adult') and (ISCLIPPED contains 'clipped')
then ('Adult Clipped')
else if (ISADULT contains 'adult') and (ISCLIPPED contains 'Not Clipped')
then ('Adult Not clipped')
else ('NA')
if ((ISADULT contains 'adult') and (ISCLIPPED contains 'clipped'))
then ('Adult Clipped')
else (
if ((ISADULT contains 'adult') and (ISCLIPPED contains 'Not Clipped'))
then ('Adult Not clipped')
else ('NA')
)
But that logic won't work because 'Not Clipped' contains 'Clipped' so that would also produce 'Adult Clipped'.
How about this?
if ((ISADULT contains 'adult') and (ISCLIPPED contains 'Not Clipped'))
then ('Adult Not clipped')
else (
if ((ISADULT contains 'adult') and (ISCLIPPED contains 'clipped'))
then ('Adult Clipped')
else ('NA')
)
And since you're using IF-THEN-ELSE rather than CASE-WHEN-THEN-END, there may be a concern about case-sensitivity -- depending on how Cognos decides to process it.
Related
I'm very new in using Cognos report studio and trying to filter some of the values and replace them into others.
I currently have values that are coming out as blanks and want to replace them as string "Property Claims"
what i'm trying to use in my main query is
CASE WHEN [Portfolio] is null
then 'Property Claims'
ELSE [Portfolio]
which is giving me an error. Also have a different filter i want to put in to replace windscreen flags to a string value rather than a number. For example if the flag is 1 i want to place it as 'Windscreen Claims'.
if [Claim Windscreen Flag] = 1
then ('Windscreen')
Else [Claim Windscreen Flag]
None of this works with the same error....can someone give me a hand?
Your first CASE statement is missing the END. The error message should be pretty clear. But there is a simpler way to do that:
coalesce([Portfolio], 'Property Claims')
The second problem is similar: Your IF...THEN...ELSE statement is missing a bunch of parentheses. But after correcting that you may have problems with incompatible data types. You may need to cast the numbers to strings:
case
when [Claim Windscreen Flag] = 1 then ('Windscreen')
else cast([Claim Windscreen Flag], varchar(50))
end
In future, please include the error messages.
it might be syntax
IS NULL (instead of = null)
NULL is not blank. You might also want = ' '
case might need an else and END at the bottom
referring to a data type as something else can cause errors. For example a numeric like [Sales] = 'Jane Doe'
For example (assuming the result is a string and data item 2 is also a string),
case
when([data item 1] IS NULL)Then('X')
when([data item 1] = ' ')Then('X')
else([data item 2])
end
Also, if you want to show a data item as a different type, you can use CAST
I have an array of strings and I am trying to look for the string that matches a certain regex. As soon as it finds the first match, I would like to break/exit out of the each loop. My code is
imagePathPrefix = "aab"
destinations.each{
if(it.startsWith(imagePathPrefix)){
// As soon as the first match is found, do something and then exit out of each !
}
destination looks like
[aabb, aabbbbb, abbbb, aaaaaabb, abababa]
As soon as it matches with aabb, I would like to exit/break out of the each loop.
EDIT:
Ive added return true but it does not work
destinations = ['aabb', 'abbbb', 'aaaaaabb', 'abababa']
println destinations
println destinations.getClass()
destinations.each{
if(it.startsWith('aab')){
println "a found"
return true
} else {
println "a not found"
}
}
Result:
[aabb, abbbb, aaaaaabb, abababa]
class java.util.ArrayList
a found
a not found
a not found
a not found
The groovy way to find the first element of a collection that meet some condition is to use find
println destinations.find {it.startsWith(imagePathPrefix)}
returns for your data
aabb
I have a multi-layered CASE statement, and one of the conditions needs to reference a table via a "not exists". I keep getting the error about 'correlated subqueries not allowed". How can I reference a table along with a condition inside a CASE statement? Below is a portion of my code:
WHEN ...... previous condition
WHEN ( CCOB_CLIENT_LOB_ID = 2 AND OI_CARRIER_LOB_ID IN (1,2,12,13) )
and not exists ( select S.STATE
FROM CCOB_PACIFICSOURCE.V_SELFPAY_COB_STATES S
WHERE S.STATE = SELFPAY_COB_STATE ) then 'NONE'
WHEN .... subsequent condition
The short answer is: you cann’t.
The longer answer is that you have to rewrite the query to outer join the table you give the alias S.
Then it’s quite possible to test for NULL.
Watch out for dublicates on the S.state column though :)
I currently have two separate saved search columns for these two statements, and I'm hoping to combine them and list the data in just one column. I've tried OR AND, but the results then error out.
First Statement
Case when {item.custitem54} is null then {quantity} else null end
Second Statement
Case when {item.custitem54} = 'Yes' and {shipdate} between to_date('05/25/2020', 'MM/DD/YYYY') and to_date('12/25/2020', 'MM/DD/YYYY') then {quantity} else null end
You can have multiple WHEN in a case statement. The first matched WHEN determines the result unless it gets to the ELSE.
Case when {item.custitem54} = 'Yes'
and {shipdate} between date '2020-05-25' and date '2020-12-25' then {quantity}
when {item.custitem54} is null then {quantity}
else null
end
I have a list which contains two types of text. One type is used for authorization while other type is used for all other purposes.
The type used for authorization always uses the same text + some code after it.
I would like to compare content of these two types of text and separate them based on content.
My idea is to look for pattern in authorization type and if it matches the pattern then this would be marked as authorization, otherwise it would be marked as "other".
I researched about comparison of patterns in Groovy, but all variations I tried did not work for me. Here is the part which should do the comparison, I am obviously doing something wrong but I don't know what.
jdbcOperations.queryForList(sql).collect { row ->
if(assert (row['MSG'] ==~ /token/)){
mark as authorization
}
else{
mark as other
}
}
Sorry for the vague code, I can not share more than this.
I think you just missing the match for the rest of the text, since you are looking only for the first part to match.
assert ("abc" ==~ /abc/) == true
assert ("abcdefg" ==~ /abc/) == false
assert ("abcdefg" ==~ /abc(.*)/) == true // <--- This can also be made more complicated