COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: que1983 on 04 Oct 2016 02:14:08 PM

Title: String code using like operator not working
Post by: que1983 on 04 Oct 2016 02:14:08 PM
CASE WHEN (refi=1 and (substring([Processing Center],1,2)= 'CD')THEN 1
ELSE 0
END

CASE WHEN ([Refi]=1 and [Processing Center] like 'CD%')THEN 1
ELSE 0
END

I am trying to pull/query records in the Processing Center field that start with CD. Example CD-Richmond, CD-Atlanta.  I tried it with 2 different queries and come up empty.  I have no idea why.  Is there an issue with the logic???
Title: Re: String code using like operator not working
Post by: MFGF on 05 Oct 2016 04:28:27 AM
Quote from: que1983 on 04 Oct 2016 02:14:08 PM
CASE WHEN (refi=1 and (substring([Processing Center],1,2)= 'CD')THEN 1
ELSE 0
END

CASE WHEN ([Refi]=1 and [Processing Center] like 'CD%')THEN 1
ELSE 0
END

I am trying to pull/query records in the Processing Center field that start with CD. Example CD-Richmond, CD-Atlanta.  I tried it with 2 different queries and come up empty.  I have no idea why.  Is there an issue with the logic???

Hi,

In the first expression you appear to have more open parentheses (3) than close parentheses (2)? That's an obvious syntax issue. Refi would also need to be in square parentheses [refi]

Where are you trying to use these expressions? In a query calculation or in a filter? If the former, are you seeing 1 and 0 values returned?

If the latter, you're taking the wrong approach. A filter should evaluate to true or false, so an appropriate expression would be:

[refi] = 1 and substring([Processing Center],1,2) = 'CD'

Cheers!

MF.