Sub Query selection based on parameter value selected

I have a parameter, and based on the value selected, I want to run one of two queries. I thought I could do either an IF THEN ELSE, or a CASE, but neither seem to be working.
What I'm trying to do is this:
IF parameter_value = 338 THEN
(RUN THIS SELECT QUERY)
ELSE
(RUN THIS SELECT QUERY)
END IF
or
SELECT CASE WHEN parameter_value = 338 THEN (RUN THIS SELECT QUERY)
ELSE (RUN THIS SELECT QUERY)
END X
I'm getting errors with both. For the CASE statement, it says "too many values". For the IF statement, it just says "invalid SQL statement".
Any suggestions would be appreciated.
Thanks.

Looks like this is what you want
SQL> WITH T
  2       AS (SELECT LEVEL col
  3             FROM DUAL
  4           CONNECT BY LEVEL <= 5)
  5  SELECT *
  6    FROM T;
       COL
         1
         2
         3
         4
         5
SQL>
SQL> VARIABLE parameter_value    NUMBER
SQL> EXEC    :parameter_value := 338;
PL/SQL procedure successfully completed.
SQL>
SQL> WITH T
  2       AS (SELECT LEVEL col
  3             FROM DUAL
  4           CONNECT BY LEVEL <= 5)
  5  SELECT col
  6    FROM T
  7   WHERE col = DECODE (:parameter_value, 338, col, :parameter_value);  --- If 338 then select all if not 338 select only the one with parameter_value.
       COL
         1
         2
         3
         4
         5
SQL>
SQL> EXEC :parameter_value := 2;
PL/SQL procedure successfully completed.
SQL>
SQL> WITH T
  2       AS (SELECT LEVEL col
  3             FROM DUAL
  4           CONNECT BY LEVEL <= 5)
  5  SELECT col
  6    FROM T
  7   WHERE col = DECODE (:parameter_value, 338, col, :parameter_value);
       COL
         2
SQL>
SQL> EXEC :parameter_value := 3;
PL/SQL procedure successfully completed.
SQL>
SQL> WITH T
  2       AS (SELECT LEVEL col
  3             FROM DUAL
  4           CONNECT BY LEVEL <= 5)
  5  SELECT col
  6    FROM T
  7   WHERE col = DECODE (:parameter_value, 338, col, :parameter_value);
       COL
         3
SQL> You need to use following where clause in your query
WHERE column_name = DECODE (parameter_value, 338, col, parameter_value); -- replace the column_name with name of the column you are comparing against.G.
Edited by: G. on Mar 8, 2011 3:36 PM
formatted and added comments

Similar Messages

  • SSRS Matrix report to show or hide year column based on parameter value "Date" selected.

    Hey experts!
    I have a requirement an ssrs matrix report should display columns (year/s) based on parameter value (date/s). 
    My Dataset fileds are: Product, Year_name, Month_name, Date
    Currently my report output looks like this-
    Param Date: 2013-08-01 00:00:0.000
    Product +Calender2011      +Calender2012     -Calender 2013........                        +Calender2014
                             Total
                      Total Jan13  Feb 13  Mar13..  Dec13   Total           Total
    Abc                      100
                        220
    10      20         30.......  20       250              400
    Xyz 110
    200 50      80         40.......  30       450              600
    My requirement:  if I'm selecting Date parameter value as '2013-xx-xx' I should only able to see Year column 'Calender2013' and rest of the years should hide. Similarly If I'm selecting Date parameter value as '2014-xx-xx' I should only able to
    see Year column 'Calender2014' .
    Appreciate your kindly help. 
    Afan

    Hi Afan,
    According to your description, you want to only show the selected year on your report, right?
    In this case, you need to get the year from the date parameter using the expression below
    =Year(Parameters!Date.Value)
    And then use the expression below to get the year from Year_Name field.
    =Right(Fields!Year_Name.Value,4)
    Then add a filter to the dataset to filter the data like below
    Expression:=Year(Parameters!Date.Value)
    Operator:=
    Value:=Right(Fields!Year_Name.Value,4)
    Reference
    http://msdn.microsoft.com/en-IN/library/dd255287.aspx
    If you have any questions, please feel free to ask.
    Regards,
    Charlie Liao
    TechNet Community Support

  • F4 help for select options based on parameter value

    hi all,
    I need a help to create an F4 help for select options for object id based on parameter value of object type, I mean once an object type is given the f4 help should contain object id's only of that type for each option.
    Regard's,
    Girija
    Moderator Message : Duplicate post locked. Continue with [f4 help for select options based on parameter value |f4 help for select options based on parameter value;.
    Edited by: Vinod Kumar on May 17, 2011 1:36 PM

    hi all,
    I need a help to create an F4 help for select options for object id based on parameter value of object type, I mean once an object type is given the f4 help should contain object id's only of that type for each option.
    Regard's,
    Girija
    Moderator Message : Duplicate post locked. Continue with [f4 help for select options based on parameter value |f4 help for select options based on parameter value;.
    Edited by: Vinod Kumar on May 17, 2011 1:36 PM

  • How do I change the query based on parameter value

    hi,
    Based on parameter value I want to change my query. If paramter value is 'O' i want the 'order by depno' in query if the value is null i don't want the order by clause.
    How do I achieve this.
    Thanks
    Ram

    U can use lexical parameter
    i.e u create one user parameter and in query
    u use this parameter with &param_name
    ex.
    select val,prize from stock where sr_no > :srno
    orderby &ord_by
    here ord_by is lexical parameter
    and set its intial value to 'sr_no'
    so u can get result order by sr_no
    this parameter is set from form so u will give condition in form and depending
    on condition u will pass this parameter from form.

  • Report based on parameter values

    Morning all,
    I have to create a report which includes Account Number, Account Name, Sales prices. There has to be two optional parameters, Account number (Static) and Product Description (Dynamic).
    I have setup the report with Account Number (Grouped), Account Name. The report works fine, when a user selects a particular account number, the report produces fine.
    Things I would like to do and know about:
    1: when it comes to sales price, it should reflect to what user has selected under Product Description parameter.
    for example if the user has selected Supra, Supra KNT, Rimless, Metal etc from the description parameter, the report should only show those selected prices according to the account number (showing descriptive field value).
    2: Additionally, if user chooses all of the options from the drop down menu (multiple selection dexcription parameter) then the report should show all the prices according to the description (showing the description field value).
    The problem in this case which I think would be is because the description values are quite alot, I mean more than 25 values and if a user selects multiple values, lets say all, how would Crystal adjust that into a report?
    Example of a report
    Parameters
    =============
    Account Number:
    Description: Supra, Supra KNT, Metal, Plastic, Rimless, Rimless KNT (multiple selection)
    Report Layout
    ============
    Account Number --- Account Name --- Supra - Supra KNT - Metal - Plastic - Rimless - Rimless KNT
    (Where Supra to Rimless KNT options are chosen by Descriptive parameter value - if not chosen then report will only show account number and account name).
    If however only Supra is selected then the report would look like this
    Report Layout
    ============
    Account Number --- Account Name --- Supra
    Any ideas how to achieve this kind of report? I have setup the report in a landscape so that we can fit as many description values as possible but I only managed to show 9, rest goes over the page.
    The report in the end has to be exported to excel so I don't mind if it goes over a page.
    Regards
    Jehanzeb

    Jehanzeb,
    You do want to use cross tabs...
    Have your database query produce a table with the following columns:
    Account Info (Number & Name)
    Product Description
    Sales
    e.g.,
    Select AcctNo + " - " + AcctName as AcctInfo,
       ProdDesc,
       sum(Sales) as Sales
    from SalesTable
    group by AcctNo, AcctName, ProdDesc
    Then use record selection to limit the data to the selected products.
    Yes, the layout of a cross tab is a bit strange, in that the design of the cross tab only shows one column for the data, but the table will expand with the underlying data.  If 4 products are selected, there will be 4 columns of sales numbers.  When setting up the cross tab, make the AcctInfo field the row header, and the ProdDesc field the column header, and the Sales field the table cell value.
    HTH,
    Carl

  • Hide column based on parameter value

    Hi All,
    I have requirement where i need to hide one column based on my input parameter value.per example
    if my parameter say DISPLAY is Yes then i need to hide the column AMOUNT..
    how to achieve this... Please help.
    Thanks
    Bharat

    Hi Bharat,
    You can do it following the steps explained in the documentation :
    http://docs.oracle.com/cd/E12844_01/doc/bip.1013/e12187/T421739T481157.htm#4535373
    regards
    Jorge
    p.s. If this answers your question then please grant the points and close the thread

  • Order by clause  based on parameter value

    hi,
    i am using reports 6i with 10 g db
    I have to create a report sorted in order of four fields. there is a parameter for selecting which field should come first in order by clause.
    ie the user has provision to view the report in selected sorted order
    suppose the four fields are emp_id, name, dept_id, desig .
    if the user select dept_id , then the order by clause should be in order of dept_id,emp_id,name,desig
    Please help to solve this scenario.
    Thanks

    Hi Rinz,
    Use the query as follows :
    select column_name1, column_name1, ....
    from  table_name
    &order_by_clauseNow in the AFTER-PARAMETER-FORM trigger set the order by clause as below depending upon requirements :
    if :sort_column = dept_id then
      :order_by_clause := 'order by dept_id,emp_id,name,desig';
    else
      :order_by_clause := 'order by emp_id, dept_id, name,desig';
    end if;
    Here sort_column is User parameter which will be selected by user, provide list of Values for it.
    Hope this helps
    Best Regards
    Arif Khadas

  • Show new page table record based on parameter value in first page in ADF

    I have to show a selected record on a new page whose input query value is in first page. For example I choose to edit an order id  by selecting order id and then pressing Edit Record button then in new page selected order record should show. I am working in ADF JSF pages. I can pass parameter from one page to another by pageFlowScope. but how to display selected record on next page.

    any one to help. I want to use an input parameter on first page to edit the table on new page

  • Query performance based on condition value

    Hi,
    I have a simple query which is actually on a view dwdb_dba.actl_partinfo_cust. Please see query bellow
    select * from dwdb_dba.actl_partinfo_cust WHERE insertdatetime=(select max(insertdatetime)
    from dwdb_dba.actl_partinfo_cust Where system_source='UTS') AND SUPPLIERID='CG1' and Custdevice in ('BT-M2789-C')This query is taking very very long time to return (around 30 records) but if i u
    Here if i change the condition "AND SUPPLIERID='CG1'" to "AND SUPPLIERID='DUMMY'", it returns within 3 seconds. Execution plan is same for both then why one query taking too much time and other returning so fast and how can i tune the query against the condition AND SUPPLIERID='CG1' so that it can also return within 3 seconds.
    I actualy dont understand the behaviour
    PLAN_TABLE_OUTPUT
    Plan hash value: 3622663398
    | Id  | Operation                       | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                |                             |    10 | 42790 |   152K  (6)| 00:00:59 |
    |*  1 |  VIEW                           | ACTL_PARTINFO_CUST          |    10 | 42790 | 59972   (4)| 00:00:23 |
    |   2 |   UNION-ALL                     |                             |       |       |            |       |
    |*  3 |    TABLE ACCESS BY INDEX ROWID  | ACTL_PARTINFO_CUST_UTS      |     9 |  3429 | 59968   (4)| 00:00:23 |
    |*  4 |     INDEX RANGE SCAN            | ACTL_PART_CUST_UTS_IDX3     |   420K|       |  1462  (11)| 00:00:01 |
    |*  5 |    TABLE ACCESS BY INDEX ROWID  | ACTL_PARTINFO_CUST_PROMIS_4 |     1 |   311 |     4   (0)| 00:00:01 |
    |*  6 |     INDEX RANGE SCAN            | ACTL_PARTINFO_CUST_4_IDX1   |     1 |       |     3   (0)| 00:00:01 |
    |   7 |   SORT AGGREGATE                |                             |     1 |    14 |            |       |
    |   8 |    VIEW                         | ACTL_PARTINFO_CUST          |  1363K|    18M| 92040   (8)| 00:00:36 |
    |   9 |     UNION-ALL                   |                             |       |       |            |       |
    |* 10 |      TABLE ACCESS BY INDEX ROWID| ACTL_PARTINFO_CUST_UTS      |  1363K|    33M| 92036   (8)| 00:00:36 |
    |* 11 |       INDEX RANGE SCAN          | ACTL_PART_CUST_UTS_IDX1     |  1481K|       |  5528  (10)| 00:00:03 |
    |* 12 |      TABLE ACCESS BY INDEX ROWID| ACTL_PARTINFO_CUST_PROMIS_4 |     1 |    15 |     4   (0)| 00:00:01 |
    |* 13 |       INDEX RANGE SCAN          | ACTL_PARTINFO_CUST_4_IDX1   |     1 |       |     3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------------------------------Thanks

    Salman Qureshi wrote:
    This query is taking very very long time to return (around 30 records) but if i u
    Here if i change the condition "AND SUPPLIERID='CG1'" to "AND SUPPLIERID='DUMMY'", it returns within 3 seconds.
    My developer has changed the code of the view which was involved and not it is working fine but still i m curious to know that what could be the reason of this. Same execution plan but only condition value is different. One value returns some rows but returns within few seconds and other condition also returns a few rows but may hours.Salman,
    A bit more details would help diagnose the root cause.
    If you are still interested in diagnosing the root cause, you may want to provide complete EXPLAIN PLAN output, along with predicate section. If you are on 10g, you may want to provide the output of DBMS_XPLAN.DISPLAY_CURSOR which will show the actual plan used along with actual number of records generated by each step in the execution plan.
    It is possible that SUPPLIERID column data is skewed so that there are less records in table for the value 'DUMMY' but much more number of records for the value 'CG1'. This predicate combined with the other predicate on CUSTDEVICE column may have been resulting in similar number of rows the final query returns.
    It is possible that the predicate on CUSTDEVICE is being applied at different stage in the plan than the predicate on SUPPLIERID column.
    Edited by: user503699 on Aug 3, 2010 3:11 PM

  • RE: Swapping two query views based on filter value

    Hi Can anyone tell me how do I swap between two query views for a web item based on one filter selection.
    Thanks in advance
    Message was edited by:
            Chandra Hasa Reddy Samala

    Hi,
    If you want to copy list item with Person column to another list, here are two solutions for your reference:
    1.Use SharePoint Designer workflow to create item in another list when there is item added in the current list, there is a workflow action “Create List Item”
    will meet your requirement. The string in Person column will still be a hyperlink in the other list and you can apply filter on it.
    Workflow actions quick reference
    http://msdn.microsoft.com/en-us/library/office/jj164026(v=office.15).aspx
    2.Use JavaScript Client Object Model to copy item to other list, you can put the script into a Content Editor Web Part.
    JavaScript Client Object Model
    http://msdn.microsoft.com/en-us/library/office/hh185006(v=office.14).aspx
    More information about
    using JavaScript Client Object Model to retrieve and create/update list item:
    http://msdn.microsoft.com/en-us/library/office/hh185007(v=office.14).aspx
    http://msdn.microsoft.com/en-us/library/office/hh185011(v=office.14).aspx
    Best regards
    Patrick Liang
    TechNet Community Support

  • Sub query returns more than 1 value?? how to solve this issue ?

    Here my query is given below
    Declare @a as NVARCHAR(50)
    Declare @b as FLOAT
    SET @a=(SELECT U_WOType FROM IGE1 WHERE ItemCode=$[$13.1.0])
    SET @b=(SELECT $[$13.U_Quantity.Number])
    IF @a='Zinc Yellow Plating'
    BEGIN
    SELECT(@b * 14)
    END
    ELSE IF @a ='Powder Coating'
    BEGIN
    SELECT(@b * 16)
    END

    Hi Karthick,
    @b should be declared as DECIMAL(19, 6).
    For a strange reason, string fields read from the UI are of full size. So to be able to a test against a specific value (IF @A and ELSE IF @a lines) you have to trim the value first.
    So the line with the SET @a = (...) should be SET @a = RTRIM (LTRIM (...))
    From a SQL-Server point of view, you can also combine the two SET @a and SET @b into a single SELECT @a=..., @b=...
    Small performance improvement, with exactly no issues.
    The IF - ELSE IF test has a condition where it returns nothing (intended ?)...
    I personally would have written it like this:
    Declare @a as NVARCHAR(50)
    Declare @b as DECIMAL (19, 6)
    SELECT @a = LTRIM (RTRIM (SELECT U_WOType FROM IGE1 WHERE ItemCode=$[$13.1.0] AND IGE1.BaseRef=$[$13.61.0])), @b = (SELECT $[$13.U_Quantity.Number])
    SELECT
    CASE @a WHEN @a = 'Zinc Yellow Plating' THEN (@b * 14)
    WHEN @a ='Powder Coating' THEN (@b * 16)
    ELSE 0.0
    END
    Regards,
    Eric

  • Conditional formatiing based on Parameter value

    Hello All,
    I am having rdf report .It has two layouts(One for English and other for germany). Based on the Language paramter passed corresponding Layout is selected.
    But how could we achieve the same using XML Publisher.
    We can simply write a If statement saying if :P_language='English'
    But how do we refer the Input parameter :P_Lnaguage in the template builder and how do we write the if statment.
    Please let me know.
    Kind Regards,
    Kumar.

    Hi,
    at the top of yor layout template define your parameter in a form field:
    <?param@begin:P_language?>
    Then you can use this parameter in a if-condition:
    <?if $P_language='English'?>
    Regards
    Rainer

  • Querying Leads based on checkbox value

    Hi I want to retrieve all the Leads based on my cpo_modified checkbox field.
    I'm using this to do it:
    objListOfLead = LeadHelper.createListOfLead(strLeadDim);
    objListOfLead[0].cpo_modified = "Y";
    //Campos de la entidad Lead a devolver
    objListOfLead[0].Country = "";
    objListOfLead[0].cpo_atInstallments = "";
    objListOfLead[0].cpo_atProfit = "";
    objListOfLead[0].cpo_atProfit_percent = "";
    (and some more, all empty too)
    objQryOutput = queryLeads(objListOfLead, mySession, false);
    But I've been unable to get what I want. I'm getting allways the same error:
    El campo 'ZBool_10' de la instancia del componente de integraci??n 'Lead' contiene una expresi??n de consulta no v??lida: 'Y'(SBL-EAI-13002)
    Any of you knows how to filter a query based on a checkbox value? Should I use "Y"or "1" or "true" perhaps???....I've tried many times with different expressions but all of them has been unsuccesfull to me...some ideas?
    Thank you very much!
    Noël

    Great Michael! The expression you suggested ='Y'" worked perfectly!
    Thank you VERY MUCH!
    But, why those kind of ¿tricks? are not well documented by Oracle? I've lost a great amount of time (been the first time I work over OnDemand) and that's a thing I really hate...
    My most sincerely thanks Michael!
    Noël

  • Retrieve All records and display in Report using CAML query in Report Builder if Parameter value is blank

    Hello Experts,
    i have created a report where i have one parameter field where user will pass parameter(e.g. EmpId). As per parameter record will fetched to report if no parameter is passed then it will display all records. I have done it by taking SqlServer Database as datasource.
    by using Following method
    Now i would like to do it by taking Sharepoint List as Datasource. For that what would be the CAML Query.
    Here is my existing CAML query.
    <RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <ListName>Employees</ListName>
      <ViewFields>
        <FieldRef Name="Title" />
        <FieldRef Name="FirstName" />
        <FieldRef Name="LastName" />
        <FieldRef Name="FullName" />
        <FieldRef Name="UserName" />
        <FieldRef Name="Company" />
      </ViewFields>
      <Query>
        <Where>  
    <Eq> 
        <FieldRef Name="Title" />
      <Value Type="Text">    
       <Parameter Name="EmployeeId"/>    
    </Value>
    </Eq>                  
        </Where>
      </Query>
    </RSSharePointList>
    The above code is working if i am passing an employeeId to Parameter. If nothing is passed, it is Not retrieving any record.
    Please suggest
    Thank you
    saroj
    saroj

    Your problem follows the well-established pattern of using an "All" parameter filter in SSRS. There are a few approaches depending on the size of your data. The easiest one is to return all data from CAML and then filter it within SSRS, the following thread
    provides some examples,
    http://stackoverflow.com/questions/18203317/show-all-records-some-records-based-on-parameter-value.
    Other options include passing all of the possible values within the CAML query when "All" is selected, using multiple Report Files to distinguish between both CAML queries, or to use multiple datasets with some logic to show/hide the correct one.
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Passing values dynamically Froman 'INLINE Query' to a 'SUB QUERY'

    If I am using an line query which uses a SELF JOIN subquery
    how can I pass the values from the Inline Query to Subquery ?
    Is this possible?
    SQL...Code
    and Inline Queries..
    (select count(*) 'PrimaryISIN'
    from instrument ins,
              instrument_xref insx
    where ins.id_inst = insx.id_inst
    and     insx.flg_active = 'Y'
    and     ins.id_source   ='MF'
    and     ins.flg_primary_listing = 'Y'
    and     ins.flg_active = 'Y'
    and     insx.id_inst_xref = (  select  DISTINCT  a.id_inst_xref
                                    from    instrument_xref a,
                                            instrument_xref  b
                                      where b.id_inst_xref ='B0DV8Y9'
                                            and     b.id_inst = a.id_inst
                                         and     b.id_inst_xref_type in ('SE','IS')
                                      and    a.id_inst_xref =  'GB00B03MLX29'
    )PISIN2
    I am hardcoding the id_inst_xref is the SELF JOIN? Can these be passed dynamically from
    the INLINE Query which is invoking the SUB QUERY?

    Hi, The hardcoded values entered in the SELF JOIN run fine.
    Now,I need to pass values dynamically from the INLINE query.
    How do I do that?
    Thanks

Maybe you are looking for

  • How do I switch my iphone 4s from one apple id to another apple id?

    How can I switch my phone from one Apple ID to another Apple ID and keep all my apps/information? I want to use the same ID between my ipod and iphone. Is this possible?

  • I created 2 iCloud accounts but I would like to remove my old one from my apple ID in order to add my new one

    I have had the same apple ID for years but I had to change my emails around including my iCloud, I wasn't entirely sure how to do this at first so I just set up a new apple ID with the new iCloud email address that I wanted. When I realised how diffi

  • Why won't my 5th Gen Ipod touch switch on?

    I have had my 5th Gen Ipod touch for 1 week. This morning it wouldn't switch on, the screen just stays black. Neither itunes or my computer recognise it but if I plug it into a mains charger the apple logo flashes slowly. I have tried everything sugg

  • CSS11506 + wildcard ssl cert ?

    We have a need to terminate multiple SSL websites on our CSS. So name1.test.com name2.test.com, name3.test.com etc. The problem I have found is that I need to burn 1 public VIP per SSL connection b/c they all need to use tcp 443 inbound and point to

  • IPhoto is not in app store under purchased

    hello i had to reinstall lion and after that i went to instore iphoto from the app store.  i went to purchased and i accidently hit the delete button instead of install.  so i went back to reinstall iphoto but an message came up saying ive already ha