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

Paramteter Question


sjoerd.jump
Go to solution Solved by sjoerd.jump,

Recommended Posts

Hello, I have a question about paramaters:

What i want to do is extract the MONTH from a date. and use this in a query.

So far I did the following:

Creacte parameter1
Set -> java.util.date

In query: 

select datefrom tablewhere extract(year from date) = extract(year from current_date) and extract(month from date) = extract(month from $P{parameter1})[/code]
 
Date in my databse is formatted as yyy-MM-dd
 
What am i doing wrong? Can someone help?
 
thanks
 
sjoerd
Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi, 

I think when you use parameters in a query you need to use the following notation: $P!{parameter1}. At least, in the reports I've done till now I have used parameters as mentioned. So you should set your query as follows: 

SELECT DATE

FROM TABLE

WHERE EXTRACT(YEAR FROM DATE) = EXTRACT (YEAR FROM CURREN_DATE) AND EXTRACT (MONTH FROM DATE) = EXTRACT (MONTH FROM $P!{parameter1})

Hope this helps.

Regards

Link to comment
Share on other sites

hmm, thats not working.

 

Have tried to shorten the query (since im only intresed in a month) to

 

where $P!{parameter1} = extract (month from datum)

 

If I subsitute $P(parameter1) for '5' than i see the data in my table im looking for.

 

I have set parameter1 to java.lang.double since thats the format of an extracted part of a timestamp.

Link to comment
Share on other sites

Hi sjoerd.jmp,

 What I understood here is that you want to get the Month and Year , of the date which user enters so what you can do is ,

Let user enter the date let it be $P{DATE},

Then make two more parameters suppose $P{MONTH} and $P{YEAR} but , remove the Use as prompt option for these two. 

set the default expression for  $P{MONTH} as $P{DATE}.getMonth()

and   $P{YEAR} as ($P{DATE}.getYear() +1900)   [This 1900 is added for returning the year as this returns the number of year in this current century]

Then in the SQL you can directly use 

WHERE EXTRACT(YEAR FROM DATE) =$P{YEAR} AND EXTRACT (MONTH FROM DATE) = $P{MONTH}

 

Hope that above explanation helps.

Thanks,

Ankur

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