Solved

Quick Report - data between two parameter dates

  • 11 August 2020
  • 9 replies
  • 1170 views

Userlevel 2
Badge +8

Hi,

In Quick Report, I have to get data FromDate to ToDate using a DateTime column

I used this:

WHERE o.REAL_FINISHED BETWEEN TO_DATE('&From_dd/mm/yyyy','dd/mm/yyyy') AND TO_DATE('&To_dd/mm/yyyy','dd/mm/yyyy')

 

I’m getting when we go to view report 

 

It works fine 

When I export data I’m getting this error:  Excel Plugin Error: Undefined bind variable 'from_dd' in Excel file

Any idea how to sort this issue?

icon

Best answer by Rusiru Dharmadasa 11 August 2020, 15:45

View original

9 replies

Userlevel 7
Badge +19

I think its the “/” characters in your parameter name causing the issue. Try removing that.

Userlevel 2
Badge +8

Hi @Rusiru 

It works now 

Is it possible to add comments by default when we press View Report?

I want to provide date format information.

Thanks,

Narsi.

Userlevel 7

Hi @Rusiru 

It works now 

Is it possible to add comments by default when we press View Report?

I want to provide date format information.

Thanks,

Narsi.

You add comments in the report definition, like below.

 

Userlevel 7
Badge +19

Yes, there is a dedicated box for comments when you created the SQL quick report. Hope this is what you are expecting.

 

 

Userlevel 2
Badge +8

Thank you so much @Rusiru and @anmise 

Userlevel 4
Badge +9

I would use the following, this allows the user to select it via a date selector.

trunc(REAL_FINISHED) between NVL(&ABSENCE_PERIOD.DATE_FROM,TRUNC(sysdate)) and  nvl(NVL(&ABSENCE_PERIOD.DATE_TO,&ABSENCE_PERIOD.DATE_FROM),trunc(sysdate))
Userlevel 2
Badge +8

Thanks @Jur 

Userlevel 2
Badge +8

Hi @Jur @Rusiru @anmise 

Is it possible to default/pre-populate values on the date parameter fields when we press “View Report”?

I mean date paramer fields would be populated automatically when we press “View Report”

“Date From” would be the first day of last week and “Date To” would be today’s date.

For example:

Today’s Date: 17-08-2020

From Date: 10-08-2020

To Date: 17-08-2020

 

Thanks,

Narsi.

Userlevel 7
Badge +18

I would use the following, this allows the user to select it via a date selector.

trunc(REAL_FINISHED) between NVL(&ABSENCE_PERIOD.DATE_FROM,TRUNC(sysdate)) and  nvl(NVL(&ABSENCE_PERIOD.DATE_TO,&ABSENCE_PERIOD.DATE_FROM),trunc(sysdate))

If you're going to nest NVL functions, it might be better to use COALESCE. (As a bonus, COALESCE is ANSI SQL and not Oracle-specific, so developers coming from other relational database systems may understand it.)

TRUNC(real_finished) BETWEEN COALESCE(&absence_period.date_from,
TRUNC(SYSDATE))
AND COALESCE(&absence_period.date_to,
&absence_period.date_from,
TRUNC(SYSDATE))

 

By applying a function to the view or table column before it’s compared to the user value, it forces the system to run a full scan and compute that function on every record. The database isn’t smart enough to work backwards, predict what the outcome of that function should be, and find records that satisfy the output condition. This means this query won’t take advantage of indexes if you have any (notwithstanding function indexes which aren’t often used).

If you happen to have an index on REAL_FINISHED, this next iteration of the predicate will take advantage of it. (Pick the variant you find more readable.)

real_finished BETWEEN COALESCE(&absence_period.date_from,
TRUNC(SYSDATE))
AND COALESCE(&absence_period.date_to,
&absence_period.date_from,
TRUNC(SYSDATE)) + (1 - (1 / (60 * 60 * 24)))

real_finished BETWEEN COALESCE(&absence_period.date_from,
TRUNC(SYSDATE))
AND COALESCE(&absence_period.date_to,
&absence_period.date_from,
TRUNC(SYSDATE)) + (86399 / 86400)

If you know your REAL_FINISHED is always truncated back to midnight, then that would make your query even simpler. I’m not familiar with this view, but you could look in your data to discover that.

SELECT *
FROM some_view
WHERE real_finished != TRUNC(real_finished);

Reply