views:

1133

answers:

3

I have an SSRS report that uses an Oracle datasource. I have a query;

select * from myTable t where
t.date between Date '2009-08-01' and Date '2009-08-04' + 1

This query works, both in Oracle and from SSRS. It gets all rows from myTable when the t.date column is between 08/01/2009 and 08/04/2009. The t.date column is of type Date()

Now, I want the dates to be parameters. So I changed the query to:

select * from myTable t where
t.date between Date :myDate and Date :myDate + 1

When I run this query in SSRS, it prompts me to enter a value for :myDate.

I tried 2009-08-01, '2009-08-01' both results in an oracle sql processing error: " Missing expression".

Any ideas?

A: 

Have you tried making sure the parameter is a DateTime type (it is string by default) in the Report Parameters menu?

pfunk
The syntax used is for string variables (ie Date *string*)
Gary
This is incorrect. IIRC the problem won't be solved by using datetime data type. The problem is with using a parameter name twice.
Emtucifor
+1  A: 

Just because you have used :myDate twice doesn't mean that they are the same. They are placeholders, and since you have two placeholders you need two values.

Gary
@Saobi - This is correct in my experience. You can't repeat a parameter, so I think that's why the WITH method Brian gave works. Alternately, you can make it :myDate2 and bind the same SSRS parameter to it as :MyDate.
Emtucifor
+1  A: 

If you insist on having one parameter (:myDate), using a with clause can make the process a bit cleaner. I'm not familar with the syntax you have in your example (i.e. the 'Date' like casting in the query), below is a SQL only implementation.

with
 select TRUNC(TO_DATE(:mydate, 'yyyy-mm-dd')) p_date from dual as parameters
select t.* 
from 
  myTable t, 
  parameters 
where
  trunc(t.date) between parameters.p_date and parameters.p_date + 1
Brian