Question : SSRS multiple parameters

Hi,
I am using SSRS  , going against informix database. I amusing Visual Studio 2008.
Here is my SQL that works in Informix:

  SELECT DISTINCT oh.order_num,oh.status_cd as po_status,
       oh.order_date as order_date , oh.received_date
  FROM order_hdr oh  
 WHERE oh.po_type IN (7)  
  AND oh.status_cd not in (7)
  and oh.order_date between today-200 and today   -- important so that we will not get thousands of data
  and oh.order_date between '2/12/2010' and '3/12/2010'
  and oh.received_date between '01/10/2010' and '03/15/2010'
 
  Note: if I take the apostrophe away from the dates, then, Informix will return no data. So, the apostrophes are important.
 
  Now, for the SSRS report, I am trying to build the SQL similar to the above example.
  I kept getting the following error:
  An error occurred during local report processing. Query exectution failed for dataset 'DataSet1'. IErrorInfo.GetDescription failed with E_NONINTERFACE(0x80004002).
 
  Report Setup:
  Parameters:
  @OrderDateBegin
  @OrderDateEnd
  @ReceivedDateBegin
  @ReceivedDateEnd
 
  All 4 parameters are set up for Date/Time data type, Allow Null value checked.
  Users are allow to query by date or date range for order date or received date. So, there may be as many as 4 dates, or as little as 0 dates.
 
  Here is my expression for the dataset (query)
 
  =" SELECT DISTINCT oh.order_num,oh.status_cd as po_status," &
 "      oh.order_date as order_date , oh.received_date "&
 "FROM order_hdr oh "&
 "WHERE oh.po_type IN (7) "&
 "AND oh.status_cd not in (7) "&
 "and oh.order_date between today-200 and today "&
IIF(IsNothing(Parameters!OrderDateBegin.Value) and IsNothing(Parameters!OrderDateEnd.Value),
   " and oh.order_date = today ", " ")&
IIF(not(IsNothing(Parameters!OrderDateBegin.Value)) and IsNothing(Parameters!OrderDateEnd.Value) ,
                 " and oh.order_date =  date('" + Parameters!OrderDateBegin.Value + "')", " ") &
IIF(not(IsNothing(Parameters!OrderDateBegin.Value)) and not(IsNothing(Parameters!OrderDateEnd.Value)) ,
     " and oh.order_date between  date('" + Parameters!OrderDateBegin.Value + "') and date('" + Parameters!OrderDateEnd.Value + "')"
                     , "")  &  
IIF(IsNothing(Parameters!ReceivedDateBegin.Value) and IsNothing(Parameters!RecivedDateEnd.Value),
   " and oh.received_date = today ", " ")&
IIF(not(IsNothing(Parameters!ReceivedDateBegin.Value)) and IsNothing(Parameters!RecivedDateEnd.Value) ,
   " and oh.received_date =  date('" + Parameters!ReceivedDateBegin.Value + "')", " ") &
IIF(not(IsNothing(Parameters!ReceivedDateBegin.Value)) and not(IsNothing(Parameters!RecivedDateEnd.Value)) ,
   " and oh.received_date between  date('" + Parameters!ReceivedDateBegin.Value + "') and date('" + Parameters!RecivedDateEnd.Value + "')"
                     , "")

I have tried using the ? in place of the Parameters.  That sort of works (in that I do not get the errors). But, given the the user does not have to enter any
dates, the ? will not work.  

Here are the possible permutaions of the SQL:
 SELECT DISTINCT oh.order_num,oh.status_cd as po_status,
       oh.order_date as order_date, oh.received_date as act_ship_date
FROM order_hdr oh  WHERE oh.po_type IN (7)
 AND oh.status_cd not in (7)  and oh.order_date between today -100 and today
 
 and oh.order_date = '5/1/2010'
 
 or
 and oh.order_date between '4/1/2010' and '5/1/2010'
 
 or
   and oh.received_date = '5/7/2010'
   
 or
     and oh.received_date  between '5/7/2010' and '5/20/2010'
 or
 
  and oh.order_date = '5/1/2010'
  and oh.received_date = '5/7/2010'
  or
 
    and oh.order_date = '5/1/2010'
      and oh.received_date  between '5/7/2010' and '5/20/2010'
 
 or
 and oh.order_date between '4/1/2010' and '5/1/2010'
 and oh.received_date = '5/7/2010'
 
  or
 and oh.order_date between '4/1/2010' and '5/1/2010'
   and oh.received_date  between '5/7/2010' and '5/20/2010'
 
 or
 
 no date conditions
 
working but using no dates
307610
 

Answer : SSRS multiple parameters

Figured it out. Here is the solution:

In the dataset,  (see code attatched) I have IIF statements.

In Parameters, see Image:

First paramter:
=IIF(IsNothing(Parameters!OrderDateBegin.Value) , Parameters!ReceivedDateBegin.Value,
Parameters!OrderDateBegin.Value )

Second Parameter
= iif(not(IsNothing(Parameters!OrderDateBegin.Value)),
iif(not(isnothing(Parameters!OrderDateEnd.Value)),Parameters!OrderDateEnd.Value, Parameters!ReceivedDateBegin.Value),
Parameters!RecivedDateEnd.Value)

Third Parameter:
=iif(not(IsNothing(Parameters!OrderDateEnd.Value)), Parameters!ReceivedDateBegin.Value,Parameters!RecivedDateEnd.Value)

Here is a snippet of my logic:
first parameter has to be OrderDateBegin or ReceivedDateBegin. Just test to see if value exists in one of them.

Second Parameter:
could be either the OrderDateEnd or ReceivedDateBegin.  If the first parameter is OrderDateBegin, test to see if OrderDateEnd exists. If so, second is OrderDateEnd. Otherwise, second is ReceivedDateBegin.
If OrderDateBegin is nothing, then the second parameter is ReceivedDate.

Third Parameter:
I know OrderDateBegin is populated. Question is figuring out second parameter and third. If OrderDateEnd is populated, then third parameter is ReceivedDateBegin. If OrderDateEnd is not populated, then that means ReceivedDateBegin is second, and ReceivedDateEnd is third.

confusing, yes. This is the math (logic) part of programming. I tested it. It is working as expected.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
=" SELECT DISTINCT oh.order_num,oh.status_cd as po_status," &
 "      oh.order_date as order_date , oh.received_date "&
 "FROM order_hdr oh "&
 "WHERE oh.po_type IN (7) "&
 "AND oh.status_cd not in (7) "&
 "and oh.order_date between today-200 and today "&
IIF(IsNothing(Parameters!OrderDateBegin.Value) and IsNothing(Parameters!OrderDateEnd.Value), 
   " ", " ")&
IIF(not(IsNothing(Parameters!OrderDateBegin.Value)) and IsNothing(Parameters!OrderDateEnd.Value) , 
                 " and oh.order_date =  ? ", " ") &
IIF(not(IsNothing(Parameters!OrderDateBegin.Value)) and not(IsNothing(Parameters!OrderDateEnd.Value)) , 
     " and oh.order_date between  ? and ? " , "") &
  IIF(not(IsNothing(Parameters!ReceivedDateBegin.Value)) and IsNothing(Parameters!RecivedDateEnd.Value) , 
   " and date(oh.received_date) =  ? ", " ") &
IIF(not(IsNothing(Parameters!ReceivedDateBegin.Value)) and not(IsNothing(Parameters!RecivedDateEnd.Value)) , 
   " and date(oh.received_date) between  ? and ? ", "")
Random Solutions  
 
programming4us programming4us