Jump to content

if else BUG


dragos_a

Recommended Posts

Hi,

I ecountered an error, I have a parameter (client3) that transforms a collection paramenter (client2) in a string, when nothing is selected in the collection parameter then the value of client3 is "()", so I made another paramenter (client3_null) which uses an IF statement to replace the "()" with an sql syntax but it's not working, when client3=() then it jumps directly to the else part.


Any sugestions?

Thanks,

Dragos

Code:
$P{client3} =="()" ? "(select c.client_id from clients c)" : $P{client3}
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I think you have two main problems:  the first is that I think the expression you listed is going to interpret the "then" part of your tertiary ?: operator as a string, not as a SQL statement to be executed.  I don't think these expressions have direct access to the database like that--only to returned fields (from a main query, a list, a table, etc., variables, and parameters.  The second problem is that I think the condition you're testing, the value of client3 is not "()" as you assume it is.  I don't know if that's because of the order you have your parameters defined or the data type or something else, but if it's jumping to the "else" part, something about the actual comparison isn't what you're expecting it to be.  Otherwise, assuming that you're actually printing out the value of client3_null somewhere, I believe that instead of "( )" or blank or null or whatever is currently printing, you  would see it print the text "(select c.client_id from clients c)".  Now, maybe I misunderstood:  maybe that's what you want that paramater to have in it (just the text, not the result of an SQL query), because maybe you're then going to use that text in your main query.  If so, then ignore what I'm calling "your first problem".

For the second problem, I would maybe do a few things:  (1) verify that your paramaters are defined in the correct order if the value of one depends on the value of another (as they do here), (2) make sure the data types agree with each other (it looks like both ${Pclient3} and $P{client3_null} are supposed to be strings) and check what the default values are, (3) simplify your expression until you get the ?: working:  $P{client3}=="()" ? $P{client3}+": true" : $P{client3}+": false"  --I actually already included my fourth suggestion in that example, which is (4) make sure you're printing the value of $P{client3} to be sure you know what the value really was.  In my example, I'm making sure that I'm recording what the value of $P{client3} was at the time I evaluated $P{client3_null}.  I would drag a copy of $P{client3_null} onto the TITLE band of my report and see what happens.  Once I get to where I understand what value is really in $P{client3} at that time and have it working predictably and always picking true (empty parens) vs. false (anything else) correctly, then I would change the "then" and "else" values back to what you really want them to be.

Hope that helps.

Carl

Link to comment
Share on other sites

Problem 1: Yes, I just want the text so I can use it in my main query. Sorry, I didn't specify.

Problem 2: The parameters are in the correct order, that's why I added the "2, 3 and 3_null". All parameters are strings.

I did drag $P{client3} and $P{client3_null} in the title band and the value in $P{client3} is () and $P{client3_null} always jumps to the "else" part.

How do I print the value?

Maybe just by putting $P{client3} in the title band isn't enough to get the real value.

 

Thanks for replying!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...