Jump to content
We've recently updated our Privacy Statement, available here ×

if condition in sql where statement


jasemilly

Recommended Posts

Hi guys

I have this condition

 

where IF($P{Usr_Rng}<>'All',Range = $P{Usr_Rng}, Range <> $P{Usr_Rng})

 

and it says incorrect condition near IF and I can't see whats wrong!!!!!! the parameter Usr_Rng is a string.

 

The user will be promtped with a list of Range codes and the word All as the first choice. 

 

If they choose All then this statement should be false and everything not like Range should be selected,

 

if they choose a range then the condition is true and it filters on the desired code.  But I can't see whats wrong with the syntax

Any ideas would be much appreciated

 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 If you're righting a SQL Query, try this instead...

 

 WHERE    $P{Usr_Rng}<>'All' 

 

Not sure about Range= this or that since if you're writing a query in a JasperReport, the Range needs to have meaning in Jasper as well, otherwise it'll throw an error.

Link to comment
Share on other sites

I got the If statement from a search and it works fine for them.  The user has a long list of range codes to filter on or I would like them to choose All, which would effectively mean no filter. 

 

I know you can do if statements in sql just the format a little unsure of.

 

thanks jasemilly

Link to comment
Share on other sites

I have it  working, a slight change in thought and it's much less complex.

 

the where statement now just looks like this

 

where ($P{myrange} = 'ALL') or ([id] = $P{myrange})

 

it works perfectly the user gets everything if they select all or an indiviual range if thats what they select.  I have expanded it to include a few other user options to increase flexibity with out lots of complex SQL statemtents or other form of control logic.

 

 

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...