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

dynamic where clause condition


antzjos

Recommended Posts

Hi,

 

Is it possible to dynamically add the where clause to the query depending on the parameter passed.

 

I tried the following but did not work

 

select colmn1, colmn2 from table1

$P{CLAUSE1}

 

I defined a parameter "CLAUSE" as string type and "PARAM" as Integer and assigned the value

"where id="+$P{PARAM1} to the parameter "CLAUSE".

 

Thanks

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

You need to use the exclamation mark to force inline insertion of a statement rather than a string.

 

 

Say CLAUSE contains the text where id='200BA'

 

 

select * from atable

$P{CLAUSE};

 

 

would then result in the database engine seeing this:

 

 

select * from atable "where id='200BA'";

 

 

 

Clearly wrong. But if you use the exclamation mark like this:

 

 

select * from atable

$P!{CLAUSE};

 

 

then the database engine will see this:

 

 

select * from atable where id='200BA';

 

 

which is much more betterer.

Post edited by: jmurray, at: 2007/02/14 02:39

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