BW 3.5 Subquery variable

I am working with BW3.5. I have many variables that are created by replacement path from a subquery. I currently have the problem that if I need to check the name of the subquery used by a variable I have to do a change variabel.When I do this the system sometimes comes back with a response "Specify a Technical Name" in a box named SAPVarEditor and after clicking OK the Query name in the Replacement Path area is blank. Anyone know what causes this?

Hi Armin
I am having the same SAPVarEDitor dialog pop-up on my BW3.5 system (copy of BW production) for some of the variables. It's not happening on the BW production system though. I thought you may have a solution for your question, if so, if you can kindly post them to me ..
much appreciated..
Seong

Similar Messages

  • Bind variables in custom sql subquery

    Is it possible to use bind variables in a custom sql subquery? I have a top level query built with expressions and I am using the builder.subQuery() method to execute the report query containing the custom sql.
    Thanks,
    Will

    Yes, that should be possible. Here is what to do. Make your SQL string. Where you want to bind variables, use a question mark.
    example: select empId from employee where employeeId=?
    Then you want to create a Call object. Then you can do ReportQuery rq = new ReadAllQuery (sqlCall);
    here is how to bind:
    queryParams is a Collection
    //start code
    Call sqlCall = new SQLCall();
    ((SQLCall)sqlCall).setSQLString(sqlString);
    if ((queryParams != null) && (queryParams.size() > 0)) {
         Vector sqlParameterTypes = new Vector(queryParams.size());
         Vector sqlParameters = new Vector(queryParams.size());
         Iterator iter = queryParams.iterator();
         while (iter.hasNext()) {
              Object queryParameter = iter.next();
              sqlParameterTypes.add(SQLCall.IN);
              sqlParameters.add(queryParameter);
         ((SQLCall)sqlCall).setParameterTypes(sqlParameterTypes);
         ((SQLCall)sqlCall).setParameters(sqlParameters);
    //end code
    I hope this helps. The APIe changed from 9.0.4.5 to 10.1.3 so this code is for 10.1.3. Post if you have any more questions.
    Zev.

  • Is it possible to pass a subquery with variable value ?

    Hi
    Is it possible to pass a subquery with variable as date ....which inturn is used to retrieve the value from the main query .
    For ex, this query is used to obtain the forecast details based on month and i need to obatain the month value from the sub query where the user need to select the forecast date as one of the  parameter
    select OFCT.Name,Fct1.ItemCode,sum(fct1.Quantity) as S_Qty,month(Fct1.date)as For_Month
    from Fct1,OFct
    where  Fct1.absid = ofct.absid
    and fct1.ItemCode = '26259939'
    and month(fct1.date) in (select month(fct1.date)from fct1 where fct1.date =<b> '[1%]'</b>)
    Hope somebody will respond
    Regards
    Mini

    Hi Owen,
    I have tried this query in Query Generator after trying it SQL Query Analyzer for syntax error as you had mentioned ,
    The query i have tried and is working with Analyser is :
    select OFCT.Name,Fct1.ItemCode,sum(fct1.Quantity) as S_Qty,month(Fct1.date)as For_Month
    from Fct1,OFct
    where  Fct1.absid = ofct.absid
    and FCT1.ItemCode = '4/4650017/2'
    and month(fct1.date) = '11'
    group by FCT1.itemcode,OFCT.NAme,FCT1.date
    In Query Generator when i try the same query,the Itemcode and Month need to be entered as variable, Iam able to take the item.Even the variable window shows me the Forecast date but the query throws an error 8180.
    Any help will be appreciated.
    Thank you
    Mini

  • Access a Connect By Level variable from subquery

       With curr_date_details as
        select   to_date('16-dec-09', 'dd-mon-yy') as businessdate 
              ,  trunc( to_date('16-dec-09', 'dd-mon-yy'), 'iw') as bow
              ,  to_date('23-nov-09', 'dd-mon-yy')  as bop
              ,  trunc(to_date('23-nov-09', 'dd-mon-yy'),'iy')  as boy   
              ,  3 as week_nbr
              ,  3 as per_week_nbr
              ,  12 as per_nbr
       from dual
       select  --== Week Number
                  case when level <= date_rec.per_week_nbr
                     then  level
                     when level = date_rec.per_week_nbr  + 1
                    then 6
                    when level = date_rec.per_week_nbr   + 2
                    then  7
                        when level = date_rec.per_week_nbr   + 3
                    then  0
                end as week_nbr
                --== Start Date
              , case when level <= date_rec.per_week_nbr
                     then  to_date('23-nov-23', 'dd-mon-rr')
                     when level = date_rec.per_week_nbr  + 1
                    then  date_rec.bop
                    when level = date_rec.per_week_nbr   + 2
                    then  date_rec.boy  
                         when level = date_rec.per_week_nbr   + 3
                    then  date_rec.boy  
                end as start_date
                --== End Date
               , case
                    when level <= date_rec.per_week_nbr
                    then   to_date('23-nov-23', 'dd-mon-rr')  + 6  
                      when level = date_rec.per_week_nbr  + 1
                    then  date_rec.bow + 6
                     when level = date_rec.per_week_nbr  + 2
                    then  date_rec.bow + 6
                            when level = date_rec.per_week_nbr   + 3
                    then  date_rec.bop - 1  
                 end as end_date
              --=== Dummy Column
              , case
                    when level <= date_rec.per_week_nbr
                    then ( select 1 + level as t  from dual)
                    else  100
                end as pesky_column
          from dual mydual
          inner join curr_date_details date_rec on  date_rec.businessdate = to_date('16-dec-09', 'dd-mon-yy')
          connect by level <= date_rec.per_week_nbr  + 3gives me error:
    Error at Command Line:9 Column:2
    Error report:
    SQL Error: ORA-01788: CONNECT BY clause required in this query block
    01788. 00000 - "CONNECT BY clause required in this query block"
    *Cause:   
    *Action:
    How can i access variable from subquery?
    this question was taken from another post
    Having trouble selecting from a table function

    Hi,
    Using a joiin:
    WITH     connect_by_query AS
       select  --== Week Number
                  case when level <= date_rec.per_week_nbr
                     then  level
                     when level = date_rec.per_week_nbr  + 1
                    then 6
                    when level = date_rec.per_week_nbr   + 2
                    then  7
                        when level = date_rec.per_week_nbr   + 3
                    then  0
                end as week_nbr
               --=== Dummy Column
           , LEVEL     AS lvl
           , per_week_nbr
          from curr_date_details date_rec
          connect by level <= date_rec.per_week_nbr  + 3
    SELECT       cb.week_nbr
    ,       case
                    when  cb.lvl <= cb.per_week_nbr
                    then  NVL (sd.sales, 0)
                    else  100
                end as pesky_column
    FROM           connect_by_query     cb
    LEFT OUTER JOIN      sample_data          sd     ON     sd.datakey = cb.lvl
    ORDER BY  cb.lvl
    ;You could also compute week_nbr in the main query, rather than the sub-query.
    Using a scalar sub-query:
    WITH     connect_by_query AS
       select  --== Week Number
                  case when level <= date_rec.per_week_nbr
                     then  level
                     when level = date_rec.per_week_nbr  + 1
                    then 6
                    when level = date_rec.per_week_nbr   + 2
                    then  7
                        when level = date_rec.per_week_nbr   + 3
                    then  0
                end as week_nbr
               --=== Dummy Column
           , LEVEL     AS lvl
           , per_week_nbr
          from curr_date_details date_rec
          connect by level <= date_rec.per_week_nbr  + 3
    SELECT       week_nbr
    ,       case
                    when lvl <= per_week_nbr
                    then NVL ( ( select sales from sample_data where datakey = lvl)
                    , 0
                    else  100
                end as pesky_column
    FROM       connect_by_query
    ORDER BY  lvl
    ;Notice that the sub-query connect_by_query is the same in both cases.

  • Please help: How to pass variable from main select to subquery

    I have a table with four columns (id, status, start_date and end_date) as follows. What I want is to get the difference between the statuses' start_date to find out how long it takes for the ID to change status. Basically getting the difference of the Start_dates of the statuses for the ID.
    ID         Status               Start_date          End_date
    1         NEW             02-FEB-07        02-FEB-07
    1         OLD             04-FEB-07        06-FEB-07
    1         BAD             09-FEB-07        14-FEB-07
    I had initially thought of doing this
    SELECT ID, (SELECT Start_date from tbl where Status = 'OLD' and ID = 1) - (SELECT Start_date from tbl WHERE Status = 'NEW' and ID =1) from tbl where ID = 1
    but that would not work since I have more than one id and implementing inside Java will be complicated. Please help me what I need to do .. Thank you

    Or this:
    SQL> CREATE TABLE t AS (SELECT 1 ID , 'NEW' status, '02-FEB-07' start_date, '02-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 1 ID , 'OLD' status, '04-FEB-07' start_date, '06-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 1 ID , 'BAD' status, '09-FEB-07' start_date, '14-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 2 ID , 'NEW' status, '02-FEB-07' start_date, '02-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 2 ID , 'BAD' status, '05-FEB-07' start_date, '10-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 2 ID , 'OLD' status, '07-FEB-07' start_date, '10-FEB-07' end_date FROM DUAL
    Table created.
    SQL> ALTER SESSION SET nls_date_format='DD-MON-RR'
    Session altered.
    SQL> SELECT ID,
           status,
           start_date,
           TO_DATE (start_date)
           - LAG (TO_DATE (start_date)) OVER (PARTITION BY ID ORDER BY TO_DATE
                                                                       (start_date))
                                                               diff_of_start_days
      FROM t
                                                    ID STA START_DAT                                 DIFF_OF_START_DAYS
                                                     1 NEW 02-FEB-07                                                  
                                                     1 OLD 04-FEB-07                                                  2
                                                     1 BAD 09-FEB-07                                                  5
                                                     2 NEW 02-FEB-07                                                  
                                                     2 BAD 05-FEB-07                                                  3
                                                     2 OLD 07-FEB-07                                                  2
    6 rows selected.

  • How can I remove distinct from subquery?

    Hello, I'll expose my problem, I don't know if may be is a bug.
    Suppose We have
    Table A:
    field A1 primary key
    field A2
    field A3
    Table B
    field B1 primary key
    field B2 foreig key to A(A1)
    field B3
    I use reverse tool to build objects from DB schema.
    Everything runs ok but when I want to recover A objects
    with sum(B3) from B,it doesn't runs fine.
    To achieve this I've made a class C with fields of class A and a double
    for sum. The code I've use is:
    KodoQuery query = (KodoQuery)getPersistenceManager()
    .newQuery(A.class, "this == b.b2");
    query.declareVariables("B b");
    query.declareImports("x.x.B");
    query.setResultClass(C.class);
    query.setResult("this as a, sum(b.b3) as s");
    query.setGrouping("a");
    Collection c = query.execute();
    I use PostGreSQL 7.4, and the sql that Kodo generates is like this:
    SELECT s.A1, SUM(s.C) AS c
    FROM ( SELECT DISTINCT a.A1 AS A1, s.B3 AS C
    FROM PUBLIC.A a INNER JOIN PUBLIC.B b ON (a.A1 = b.B2) ) s
    GROUP BY s.A1
    But the problem is 'DISTINCT' keyword. If I have records on B
    with same B3 value then:
    B1=1,B2=1,B3=25
    B1=2,B2=1,B3=25
    The query returns SUM(B3)=25 which is not valid!!!, it must be 50.
    It fails with repeated B3 values because distinct keyword.
    I bypass this adding a third field to class C that I will not use, and
    introduce it into query:
    KodoQuery query = (KodoQuery)getPersistenceManager()
    .newQuery(A.class, "this == b.b2");
    query.declareVariables("B b");
    query.declareImports("x.x.B");
    query.setResultClass(C.class);
    query.setResult("this as a, sum(b.b3) as s, sum(b.b1) as t");
    query.setGrouping("a");
    Collection c = query.execute();
    With this, I force to put primary key into subquery, and disables
    DISTINCT, but I never will use this field :(. SQL generated by KODO:
    SELECT s.A1, SUM(s.C) AS c, SUM(s.T) as t
    FROM ( SELECT DISTINCT a.A1 AS A1, s.B3 AS C, s.B1 as T
    FROM PUBLIC.A a INNER JOIN PUBLIC.B b ON (a.A1 = b.B2) ) s
    GROUP BY s.A1
    Questions:
    1.- What may I doing wrong?
    2.- How can I disable Distinct from subquerys?
    And, no, I don't want to select by class B and then search A objects.
    I want a C object with A object plus SUM of values from B.
    I am achieving this with this patch.
    I know that when there aren't B objects I don't receive results.
    Is there any way to build an OUTER JOIN with JDOQL ?
    In order to bypass this, I execute the query another time but reseting to
    0, but I will prefer to be able to build an OUTER JOIN ;)
    PD: Little class descriptions:
    class A{ int a1, int a2, int a3} (autogenerated by kodo)
    class B{ int b1, int b2, double b3} (autogenerated by kodo)
    class C{ A a, double c, int t} (generated by me)
    Sorry for my english :(
    thanks.

    I'll address your outer join question first, since it's the easiest. Kodo will
    create outer joins automatically as needed to satisfy your JDOQL. In this case,
    your JDOQL does not warrant an outer join. Your filter criteria on the query is
    "this == b.b2". That means the query cannot and should not return any values
    when there are no A's that match that join. Why not try this equivalent but
    simpler query?
    Query q = pm.newQuery (B.class);
    q.setResult ("b2 as a, sum(b3) as s");
    q.setGrouping ("b2");
    q.setResultClass (C.class);
    That will return results grouped by the A objects from the b2 field, and the sum
    of the b3 field for all B's in each group. It should use an outer join.
    About DISTINCT:
    The pattern of a distinct subselect is caused by two conditions:
    1. Your result clause is non-distinct. That is, you did:
    q.setResult("this as a, sum(b3) as s")
    rather than:
    q.setResult("distinct this as a, sum(b3) as s")
    This means that you want to allow duplicates in the projected values you get back.
    2. You use an unbound variable ("b") in a way that could lead to duplicates
    caused by relational joins. JDO always eliminates duplicates caused by database
    joins.
    So in order to eliminate the possible duplicates caused by #2, Kodo issues the
    query as a DISTINCT subselect. Then in order to allow duplicates of the
    projected results (#1), Kodo uses a non-distinct outer select.
    The simplest way to eliminate the DISTINCT subselect is to use the alternate
    query on B.class I mentioned above. That will result in no DISTINCTs at all.
    Another way is to use the "distinct" keyword in your setResult() call, as I
    showed in #1. That will result in a DISTINCT select without any subselect.
    Without reverting to a SQL query (which you can still execute through JDO APIs,
    as described in the documentation), I believe those are the options available.

  • Using all results in a multiple row resultset returned by a subquery

    I solved the problem of splitting up the dimension fields for each account code as referenced in my first post.  Now I am needing to return the budget amounts of each account code (some account codes return multiple amounts).  I need to do this
    for five sets of years so that I show each year in its own column (a Proposed Budget Year, a Current Budget Year, and three historical budget years).
    Right now I am attempting to use joins to the three tables that show the different types of amounts.  Some account codes will return multiple amount values for the same account code in the same year.  I need all of these amounts in a row associated
    with the account code so that I can group and sum them later on by differing criteria from the dimension fields.  Here is what I have so far (it returns the account codes and dimension fields correctly, but the amounts aren't working and I can't figure
    out how to make them work.
    USE [Financial]
    -- Input variables from web page
    DECLARE @pkYear INT;
    DECLARE @Fund INT;
    DECLARE @Function INT;
    DECLARE @FundingSource INT;
    DECLARE @OperationalUnit INT;
    DECLARE @JobClass INT;
    DECLARE @Version INT;
    DECLARE @Object INT;
    DECLARE @Instorg INT;
    DECLARE @SubMat INT;
    DECLARE @SCC INT;
    DECLARE @ExcludeNoAct INT;
    DECLARE @CurrentUser INT;
    -- Variables to calculate budget years
    DECLARE @PeriodStartDate VARCHAR(256);
    DECLARE @PeriodEndDate VARCHAR(256);
    DECLARE @ProposedBudgetYear INT;
    DECLARE @CurrentBudgetYear INT;
    DECLARE @BudgetYear1 INT;
    DECLARE @BudgetYear2 INT;
    DECLARE @BudgetYear3 INT;
    DECLARE @YearStartDateYear INT;
    DECLARE @ProposedYearStartDateYear INT;
    DECLARE @Year1StartDateYear INT;
    DECLARE @Year2StartDateYear INT;
    DECLARE @Year3StartDateYear INT;
    DECLARE @YearStartDate DATE;
    -- Set variables to test query
    SET @pkYear = 5;
    SET @ExcludeNoAct = 0;
    SET @CurrentUser = 1;
    SET @YearStartDate = (SELECT TOP 1 BeginDate FROM fiYear Y
    Where Y.pkYear = @pkYear);
    PRINT @pkYear;
    PRINT @YearStartDate;
    -- Set variables for budget years
    SET @YearStartDateYear = YEAR(@YearStartDate);
    SET @ProposedYearStartDateYear = @YearStartDateYear + 1;
    SET @Year1StartDateYear = @YearStartDateYear - 1;
    SET @Year2StartDateYear = @YearStartDateYear - 2;
    SET @Year3StartDateYear = @YearStartDateYear - 3;
    PRINT @YearStartDateYear;
    PRINT @ProposedYearStartDateYear;
    PRINT @Year1StartDateYear;
    PRINT @Year2StartDateYear;
    PRINT @Year3StartDateYear;
    -- Set budget years based on year input parameter
    SET @ProposedBudgetYear = (SELECT pkYear
    FROM fiYear
    WHERE YEAR(fiYear.BeginDate) = @ProposedYearStartDateYear)
    SET @CurrentBudgetYear = (SELECT pkYear
    FROM fiYear
    WHERE YEAR(fiYear.BeginDate) = @YearStartDateYear)
    SET @BudgetYear1 = (SELECT pkYear
    FROM fiYear
    WHERE YEAR(fiYear.BeginDate) = @Year1StartDateYear)
    SET @BudgetYear2 = (SELECT pkYear
    FROM fiYear
    WHERE YEAR(fiYear.BeginDate) = @Year2StartDateYear)
    SET @BudgetYear3 = (SELECT pkYear
    FROM fiYear
    WHERE YEAR(fiYear.BeginDate) = @Year3StartDateYear)
    PRINT @ProposedBudgetYear;
    PRINT @CurrentBudgetYear;
    PRINT @BudgetYear1;
    PRINT @BudgetYear2;
    PRINT @BudgetYear3;
    -- Query building exercise
    DECLARE @fkState INT
    DECLARE @fkDimPosFund INT
    DECLARE @fkDimPosFunction INT
    DECLARE @fkDimPosObject INT
    DECLARE @fkDimPosFundingSource INT
    DECLARE @fkDimPosInstructionalOrganization INT
    DECLARE @fkDimPosOperationalUnit INT
    DECLARE @fkDimPosSubjectMatter INT
    DECLARE @fkDimPosJobClass INT
    DECLARE @fkDimPosSpeclCostCntr INT
    SET @fkState = 40
    SET @Version = 11
    --Get the position of the fund account code dimensions determined by state
    SELECT @fkDimPosFund = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'FUND' AND @fkState = fiDimensionPosition.fkState
    SELECT @fkDimPosFunction = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'FUNCTION' AND @fkState = fiDimensionPosition.fkState
    SELECT @fkDimPosObject = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'OBJECT' AND @fkState = fiDimensionPosition.fkState
    SELECT @fkDimPosFundingSource = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'FUNDING SOURCE' AND @fkState = fiDimensionPosition.fkState
    SELECT @fkDimPosInstructionalOrganization = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'INSTRUCTIONAL ORGANIZATION' AND @fkState = fiDimensionPosition.fkState
    SELECT @fkDimPosOperationalUnit = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'OPERATIONAL UNIT' AND @fkState = fiDimensionPosition.fkState
    SELECT @fkDimPosSubjectMatter = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'SUBJECT MATTER' AND @fkState = fiDimensionPosition.fkState
    SELECT @fkDimPosJobClass = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'JOB CLASS' AND @fkState = fiDimensionPosition.fkState
    SELECT @fkDimPosSpeclCostCntr = pkDimensionPosition FROM fiDimensionPosition WHERE Title = 'SPECIAL COST CENTER' AND @fkState = fiDimensionPosition.fkState
    PRINT @fkDimPosFund
    PRINT @fkDimPosFunction
    PRINT @fkDimPosObject
    PRINT @fkDimPosFundingSource
    PRINT @fkDimPosInstructionalOrganization
    PRINT @fkDimPosOperationalUnit
    PRINT @fkDimPosSubjectMatter
    PRINT @fkDimPosJobClass
    PRINT @fkDimPosSpeclCostCntr
    SELECT ACCTCODE.fkYear
    ,Y.YearID
    ,ACCTCODE.AccountCode
    ,DIMFUND.Dimension AS [Fund]
    ,DIMFUNCTION.Dimension AS [Function]
    ,DIMOBJECT.Dimension AS [Object]
    ,(SELECT LEFT ( DIMOBJECT.Dimension , 1 )) AS [MAJOR OBJECT]
    ,DIMFUNDINGSOURCE.Dimension AS [Funding Source]
    ,DIMFUNDINGINSTRUCTIONALORG.Dimension AS [Instructional Organization]
    ,DIMOPUNIT.Dimension AS [Operational Unit]
    ,DIMSUBMATTER.Dimension AS [Subject Matter]
    ,DIMJOBCLASS.Dimension AS [Job Classification]
    ,DIMSPECLCOSTCNTR.Dimension AS [Special Cost Center]
    ,BP.Amount AS Proposed
    ,B.Amount AS [Current]
    ,T1.Amount AS [Historical]
    FROM fiAccountCode ACCTCODE
    JOIN fiDimension DIMFUND
    ON DIMFUND.fkDimensionPosition = @fkDimPosFund
    AND (DIMFUND.pkDimension = ACCTCODE.fkDimension1
    OR DIMFUND.pkDimension = ACCTCODE.fkDimension2
    OR DIMFUND.pkDimension = ACCTCODE.fkDimension3
    OR DIMFUND.pkDimension = ACCTCODE.fkDimension4
    OR DIMFUND.pkDimension = ACCTCODE.fkDimension5
    OR DIMFUND.pkDimension = ACCTCODE.fkDimension6
    OR DIMFUND.pkDimension = ACCTCODE.fkDimension7
    OR DIMFUND.pkDimension = ACCTCODE.fkDimension8
    OR DIMFUND.pkDimension = ACCTCODE.fkDimension9
    JOIN fiDimension DIMFUNCTION
    ON DIMFUNCTION.fkDimensionPosition = @fkDimPosFund
    AND (DIMFUNCTION.pkDimension = ACCTCODE.fkDimension1
    OR DIMFUNCTION.pkDimension = ACCTCODE.fkDimension2
    OR DIMFUNCTION.pkDimension = ACCTCODE.fkDimension3
    OR DIMFUNCTION.pkDimension = ACCTCODE.fkDimension4
    OR DIMFUNCTION.pkDimension = ACCTCODE.fkDimension5
    OR DIMFUNCTION.pkDimension = ACCTCODE.fkDimension6
    OR DIMFUNCTION.pkDimension = ACCTCODE.fkDimension7
    OR DIMFUNCTION.pkDimension = ACCTCODE.fkDimension8
    OR DIMFUNCTION.pkDimension = ACCTCODE.fkDimension9
    JOIN fiDimension DIMOBJECT
    ON DIMOBJECT.fkDimensionPosition = @fkDimPosFund
    AND (DIMOBJECT.pkDimension = ACCTCODE.fkDimension1
    OR DIMOBJECT.pkDimension = ACCTCODE.fkDimension2
    OR DIMOBJECT.pkDimension = ACCTCODE.fkDimension3
    OR DIMOBJECT.pkDimension = ACCTCODE.fkDimension4
    OR DIMOBJECT.pkDimension = ACCTCODE.fkDimension5
    OR DIMOBJECT.pkDimension = ACCTCODE.fkDimension6
    OR DIMOBJECT.pkDimension = ACCTCODE.fkDimension7
    OR DIMOBJECT.pkDimension = ACCTCODE.fkDimension8
    OR DIMOBJECT.pkDimension = ACCTCODE.fkDimension9
    JOIN fiDimension DIMFUNDINGSOURCE
    ON DIMFUNDINGSOURCE.fkDimensionPosition = @fkDimPosFund
    AND (DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension1
    OR DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension2
    OR DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension3
    OR DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension4
    OR DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension5
    OR DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension6
    OR DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension7
    OR DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension8
    OR DIMFUNDINGSOURCE.pkDimension = ACCTCODE.fkDimension9
    JOIN fiDimension DIMFUNDINGINSTRUCTIONALORG
    ON DIMFUNDINGINSTRUCTIONALORG.fkDimensionPosition = @fkDimPosFund
    AND (DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension1
    OR DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension2
    OR DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension3
    OR DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension4
    OR DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension5
    OR DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension6
    OR DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension7
    OR DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension8
    OR DIMFUNDINGINSTRUCTIONALORG.pkDimension = ACCTCODE.fkDimension9
    JOIN fiDimension DIMOPUNIT
    ON DIMOPUNIT.fkDimensionPosition = @fkDimPosFund
    AND (DIMOPUNIT.pkDimension = ACCTCODE.fkDimension1
    OR DIMOPUNIT.pkDimension = ACCTCODE.fkDimension2
    OR DIMOPUNIT.pkDimension = ACCTCODE.fkDimension3
    OR DIMOPUNIT.pkDimension = ACCTCODE.fkDimension4
    OR DIMOPUNIT.pkDimension = ACCTCODE.fkDimension5
    OR DIMOPUNIT.pkDimension = ACCTCODE.fkDimension6
    OR DIMOPUNIT.pkDimension = ACCTCODE.fkDimension7
    OR DIMOPUNIT.pkDimension = ACCTCODE.fkDimension8
    OR DIMOPUNIT.pkDimension = ACCTCODE.fkDimension9
    JOIN fiDimension DIMSUBMATTER
    ON DIMSUBMATTER.fkDimensionPosition = @fkDimPosFund
    AND (DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension1
    OR DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension2
    OR DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension3
    OR DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension4
    OR DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension5
    OR DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension6
    OR DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension7
    OR DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension8
    OR DIMSUBMATTER.pkDimension = ACCTCODE.fkDimension9
    JOIN fiDimension DIMJOBCLASS
    ON DIMJOBCLASS.fkDimensionPosition = @fkDimPosFund
    AND (DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension1
    OR DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension2
    OR DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension3
    OR DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension4
    OR DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension5
    OR DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension6
    OR DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension7
    OR DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension8
    OR DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension9
    JOIN fiDimension DIMSPECLCOSTCNTR
    ON DIMJOBCLASS.fkDimensionPosition = @fkDimPosFund
    AND (DIMJOBCLASS.pkDimension = ACCTCODE.fkDimension1
    OR DIMSPECLCOSTCNTR.pkDimension = ACCTCODE.fkDimension2
    OR DIMSPECLCOSTCNTR.pkDimension = ACCTCODE.fkDimension3
    OR DIMSPECLCOSTCNTR.pkDimension = ACCTCODE.fkDimension4
    OR DIMSPECLCOSTCNTR.pkDimension = ACCTCODE.fkDimension5
    OR DIMSPECLCOSTCNTR.pkDimension = ACCTCODE.fkDimension6
    OR DIMSPECLCOSTCNTR.pkDimension = ACCTCODE.fkDimension7
    OR DIMSPECLCOSTCNTR.pkDimension = ACCTCODE.fkDimension8
    OR DIMSPECLCOSTCNTR.pkDimension = ACCTCODE.fkDimension9
    JOIN faBudgetPrep BP ON ACCTCODE.pkAccountCode = BP.fkAccountCode
    JOIN fiBudget B ON B.fkAccountCode = ACCTCODE.pkAccountCode
    JOIN faTransaction T1 ON T1.fkAccountCode = ACCTCODE.pkAccountCode
    JOIN fiYear Y ON Y.pkYear = ACCTCODE.fkYear
    ORDER BY Y.YearID
    If I run the query without the amounts included, I get all the account codes and dimension fields fine.  If I try to include the amounts I get an empty result set.  I tried using a subquery to get the amounts, but it erred out due to returning multiple
    results for each account code on a given amount type in a given year.  I'm stuck.  Please help.
    RandyHJ1957

    The amounts are coming from three other tables that are not yet included in the existing query.  Depending on the year being referenced, the amounts come from the following tables:
    ProposedBudget amounts come from the BudgetPrep table (BudgetPrep.Amount).
    CurrentBudget amounts come from the Budget table (Budget.Amount)
    Each of the the historical years of budget amounts come from the Transactions table, which I call three times with different table aliases (T1, T2, T3) so that I use the following columns T1.Amount, T2.Amount, and T3.Amount for each respective historical
    year.
    For example, I want my years to appear as columns in the result set:
    ProposedBudget     Current Budget     Historical 1     Historical 2     Historical 3
    2015                       2014                    2013              2012            
      2011
    I need to join the amounts to the account codes for each year I am dealing with.
    Sometimes there are several results for the amount per account code in a year (representing different fund divisions) and I need to display all the amounts so I can group and sum them later in a report.  I'm trying to gather all the amounts for each
    account code (and its respective line items) for each of the five years so I can present the data in a report.
    RandyHJ1957

  • How to pass parameter [bind variable or substitution variable] to a view?

    How can I pass a parameter [bind variable or substitution variable] to a view in Oracle?
    Some will tell me that this is not necessary, that I can only pass the parameter when I query the view, but I found some case where this cause performance issue. In long view where I use subquery factoring [WITH], it's necessary to pass the parameter many time through different subqueries and not only to the resulting view.
    In other database (SQL Server, Access), we can pass parameters through query. I can't find how to do that in Oracle. Can some one tell me what is the approach suggest by Oracle on that subject?
    Thank you in advance,
    MB
    What I can do:
    CREATE VIEW "HR"."EMP_NAME" ("FIRST_NAME", "LAST_NAME")
    AS
    SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES;
    What I want to do:
    CREATE VIEW "HR"."EMP_NAME" ("FIRST_NAME", "LAST_NAME")(prmEMP_ID)
    AS
    SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES WHERE EMPLOYEE_ID IN (:prmEMP_ID);

    Blais wrote:
    How can I pass a parameter [bind variable or substitution variable] to a view in Oracle?
    Some will tell me that this is not necessary, that I can only pass the parameter when I query the view, but I found some case where this cause performance issue. In long view where I use subquery factoring [WITH], it's necessary to pass the parameter many time through different subqueries and not only to the resulting view.Yes, there can be performance issues. Views are a form of dynamic SQL and it is hard to predict how they will perform later.
    You can't pass parameters to a view. They are not functions. The mechanism to put the values in is what you mentioned, passing the parameter when you query the view.
    In other database (SQL Server, Access), we can pass parameters through query. I can't find how to do that in Oracle. Can some one tell me what is the approach suggest by Oracle on that subject? This functionality is not supported.
    What I can do:
    CREATE VIEW "HR"."EMP_NAME" ("FIRST_NAME", "LAST_NAME")
    AS
    SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES;
    What I want to do:
    CREATE VIEW "HR"."EMP_NAME" ("FIRST_NAME", "LAST_NAME")(prmEMP_ID)
    AS
    SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES WHERE EMPLOYEE_ID IN (:prmEMP_ID);Include the bind value when you use the view in a SELECT. The value will be applied to the view at run-time, somthing like
    CREATE  VIEW "HR"."EMP_NAME_VW" ("FIRST_NAME", "LAST_NAME","EMPLOYEE_ID")(prmEMP_ID)
    AS  SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES;
    select *
      from emp_name_vw
      WHERE EMPLOYEE_ID IN (:prmEMP_ID);To use EMPLOYEE_ID I added it to your list of columns in the view so it can be referenced in the WHERE clause. If you don't want to see that value don't select it from the view.

  • Subquery conditional execution using cbo

    hellou
    how i do for execute a subquery conditionally, using the cbo??
    i got an example:
    create table table1 AS
    SELECT * FROM (
        SELECT 1 id, 'a' boss FROM dual
       union all
        SELECT 3 id, 'b' boss FROM dual
       union all
        SELECT 5 id, 'a' boss FROM dual
       union all
        SELECT 7 id, 'b' boss FROM dual
       union all
        SELECT 9 id, 'a' boss FROM dual
    create index idx_table1 on table1(boss, id)
    create table table2 AS
    SELECT * FROM (
        SELECT 2 id, 'b' boss FROM dual
       union all
        SELECT 4 id, 'a' boss FROM dual
       union all
        SELECT 6 id, 'b' boss FROM dual
       union all
        SELECT 8 id, 'a' boss FROM dual
       union all
        SELECT 10 id, 'b' boss FROM dual
    create index idx_table2 on table2(boss, id)
    CREATE OR REPLACE FUNCTION print_hi
        isb in varchar2
    return number
    IS
    BEGIN
        dbms_output.put_Line(isb);
        return 0;
    END;
    -- the query !!!!!!!
    with data AS
        SELECT
        FROM (
            -- subquery #1
            SELECT
                1 query_name,
                id pibot,
                boss
            FROM table1
            WHERE print_hi(id) = 0
           union all
            -- subquery #2
            SELECT
                2 query_name,
                id pibot,
                boss
            FROM table2
    SELECT
        pibot + query_name / 10 pibot
    FROM data
    WHERE 1 = 1
        AND boss = :boss
        AND (
            query_name = :q
            AND pibot > :p
           OR query_name > :q )
        AND rownum <= 3i want than only the query #2 be executed.
    the query #1 print data in the screen when is executed (for the function print_hi).
    now i execute the query with the variables data as:
    boss = 'a'
    q = 2
    p = 0
    when i execute the query using rules, then not print anything in the screen.
    when i execute the query using costs, then print 1 5 9 in the screen. this means than the query #1 is being executed when this should not
    help .. tx
    SELECT * FROM v$version
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
    PL/SQL Release 10.2.0.5.0 - Production
    CORE10.2.0.5.0Production
    TNS for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production

    As often is, the predicates section of the execution plan is quite revealing on this one.
    Take your original query
    explain plan for
    with data AS
    (SELECT *
    FROM (-- subquery #1
           SELECT 1 query_name,id pibot,boss
           FROM table1
           WHERE print_hi(id) = 0
           union all
            -- subquery #2
           SELECT 2 query_name,id pibot,boss
            FROM table2))
    SELECT pibot + query_name / 10 pibot
    FROM   data
    WHERE  1 = 1
    AND    boss = :boss
    AND   (query_name = :q
    AND    pibot > :p
    OR     query_name > :q )
    AND    rownum <= 3;
    select * from table(dbms_xplan.display);gives
    | Id  | Operation           | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |            |     2 |    38 |     2   (0)| 00:00:01 |
    |*  1 |  COUNT STOPKEY      |            |       |       |            |          |
    |   2 |   VIEW              |            |     2 |    38 |     2   (0)| 00:00:01 |
    |   3 |    UNION-ALL        |            |       |       |            |          |
    |*  4 |     INDEX RANGE SCAN| IDX_TABLE1 |     1 |    16 |     1   (0)| 00:00:01 |
    |*  5 |     INDEX RANGE SCAN| IDX_TABLE2 |     1 |    16 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM<=3)
       4 - access("BOSS"=:BOSS)
           filter("PRINT_HI"(TO_CHAR("ID"))=0 AND (1>TO_NUMBER(:Q) OR
                  1=TO_NUMBER(:Q) AND "ID">TO_NUMBER(:P)))
       5 - access("BOSS"=:BOSS)
           filter(2>TO_NUMBER(:Q) OR 2=TO_NUMBER(:Q) AND "ID">TO_NUMBER(:P))Assuming that the FILTER logic in STEP 4 is followed to order, it's not then possible with this query as is to short-circuit the evaluation of PRINT_HI as it is evaluated first.
    When you make a change (just to q not necessarily to boss as well)
    from
    query_name = :qto
    query_name = 2You'll hopefully notice the difference in predicate evaluation with the extra filter step:
    | Id  | Operation             | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |            |     2 |    38 |     2   (0)| 00:00:01 |
    |*  1 |  COUNT STOPKEY        |            |       |       |            |          |
    |   2 |   VIEW                |            |     2 |    38 |     2   (0)| 00:00:01 |
    |   3 |    VIEW               |            |     2 |    38 |     2   (0)| 00:00:01 |
    |   4 |     UNION-ALL         |            |       |       |            |          |
    |*  5 |      FILTER           |            |       |       |            |          |
    |*  6 |       INDEX RANGE SCAN| IDX_TABLE1 |     1 |    16 |     1   (0)| 00:00:01 |
    |*  7 |      INDEX RANGE SCAN | IDX_TABLE2 |     1 |    16 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM<=3)
       5 - filter(1>TO_NUMBER(:Q))
       6 - access("BOSS"=:BOSS)
           filter("PRINT_HI"(TO_CHAR("ID"))=0)
       7 - access("BOSS"=:BOSS)
           filter("ID">TO_NUMBER(:P) OR 2>TO_NUMBER(:Q))

  • Use of a alias in one subquery

    Executing the command below it returns an error informing that "A1" is an invalid identification.
    select 1 as a1, (select a1 as b2 from dual) as b1 from dual
    Is not possible to create one alias and to use it in one subquery in the same command?
    It exists another form of if getting this result?

    I placed ' the changeable ' term for you understand what I really need. I go to more clearly try to be.
    I attribute to value 1 to variavel a1, and in subquery I attribute to the variable a1 to the second variable b2. And the result of this is attributed to the third variable b2.
    In the first column of mine ' select ', I create column I unite a1 to receive value 1, in the second column of mine ' select ', I make one subquery selecting column I unite a1 (first column of select) and I create as column you unite to receive the value from column you unite a1. This select must return the content from column unites a1=1 and b1=b2=a1=1.
    My problem is of this type, only that in a context of my application.
    If I to decide this basic example, I will also decide the problem of my application.
    You can make tests with as select that I passed (select 1 aa, 2 bb, (aa + bb) the dual c from).
    In this in case that, I create column you unite aa to receive value 1, I create column you unite bb to receive value 2, I add the content of the two column you unite and I create column you unite c to receive the addition, that is equal (1+2)=3.

  • DECODE is not working in WHERE clause when subquery returns more rows

    Hi Gurus,
    I want to write a query on CCENTERS table(Script given below) and expect the following result:
    1. When I pass a value of 0 for ID, It returns all the rows given in the table.
    2. When I pass a value other than 0, It returns the row for the given value as well as all its child records.
    CCENTER has parent-child relationship in ID and BASE column. I am using a query with DECODE function. but DECODE function in WHERE clause is not capable of handling sub-query with multiple rows.
    VARIABLE ParaCCenter NUMBER
    BEGIN
    :paraccenter:=0;
    END;
    CREATE TABLE ccenters
    (id NUMBER,
    name VARCHAR2(20),
    base number);
    INSERT INTO ccenters VALUES(1,'NUST',null);
    INSERT INTO ccenters VALUES(2,'SEECS',1);
    INSERT INTO ccenters VALUES(3,'NBS',1);
    commit;
    SELECT * FROM ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,
    (SELECT id FROM ccenters
    START WITH base=:ParaCCenter
    CONNECT BY PRIOR id = base
    UNION
    SELECT :ParaCCenter FROM dual
    BEGIN
    :paraCCenter:=1;
    END;
    SELECT * FROM ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,
    (SELECT id FROM ccenters
    START WITH base=:ParaCCenter
    CONNECT BY PRIOR id = base
    UNION
    SELECT :ParaCCenter FROM dual))
    The result is
    (SELECT id FROM ccenters
    ERROR at line 3:
    ORA-01427: single-row subquery returns more than one row
    How this query can be rewritten for the given functionality. Any response will be highly appreciated.
    Thanks

    And if you want to use DECODE:
    SQL> BEGIN
      2  :paraccenter:=0;
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select  *
      2    from  ccenters
      3    where :paraccenter = decode(:paraccenter,0,0,id)
      4  /
            ID NAME                       BASE
             1 NUST
             2 SEECS                         1
             3 NBS                           1
    SQL> BEGIN
      2  :paraccenter:=2;
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select  *
      2    from  ccenters
      3    where :paraccenter = decode(:paraccenter,0,0,id)
      4  /
            ID NAME                       BASE
             2 SEECS                         1
    SQL> SY.

  • Global variable in a package

    Hi,
    Can anyone tell me if this is possible?
    I have a table with some control values in it and want to be able to access some of these values in a package.
    In the spec of my package I want to be able to set a global variable for the value of a specific record.
    i.e. I want to be able to say something like:
    glo_value_1 := (select value_col from control_table where id_col = 1);
    I'm trying to avoid just creating a cursor that I will have to open/fetch/close for every procedure and function in my package. I'd like to be able to just set the value in the specification so that I can just refer to it as glo_value_1.
    Any ideas?
    Thanks
    Yog

    Well there is no support for scalar subquery in PL/SQL (in-line SELECT) but you could of course write a function to geth the control value based on it's id and assign the result of the function to the global, something like...
    glo_value_1 := control_value_function (1);

  • How to reduce different versions of SQL with bind variables

    There is an application, developed on Java.
    Application executes SQL following types:
    select * from t where id in (:1)
    select * from t where id in (:1, :2)
    select * from t where id in (:1, :2, :3)
    select * from t where id in (:1, :2, :3, :4)
    ...And as a result very many versions (thousands) of similar SQL.
    Do you know a method to reduce number of such SQLs?
    I see one method: use one form of SQL with large number of prepared bid variables.
    Like as
    select * from t where id in (:1, :2, :3, :4, :5, :6, :7, :8, ...);And if query will be executed with one variable, the others will be equal to null.
    Is there another method?

    Cannot you insert those values into a temporary table and work within a subquery against that table ? That will make the code more secure, especially if the number of values is high.
    Nicolas.

  • Error with clob column: "No pl/sql translation for the blind type given for this bind variable"

    This is reports 11g
    I've got a clob column. Reports seems to recognize its type, but if I try to reference it in a format trigger, I get this error at compile time:
    "No pl/sql translation for the blind type given for this bind variable"

    Actually, Reports is in something better than Forms.
    Neither Forms nor Reports do not have "complete" SQL engine (both have only "complete" PL/SQL engine), but have their own SQL parser, which does not understand SQL commands after the database 8.0.
    But, in Reports Data Model - SQL Query Statement, we can write "modern" SQL statement (> database 8.0), because Reports sent it directly to the database, without using their own SQL parser.
    For example, in Reports Data Model - SQL Query Statement, we can write this (scalar subquery expressions, in bold):
    select empno,
           ename,
           deptno,
           (select dname from dept where deptno = emp.deptno) dname
      from emp
    order by empno;
    although scalar subquery expressions was introduced in the database 9.0.1, and in databases 8.0 and 8.1 we should write someting like this:
    select emp.empno,
           emp.ename,
           emp.deptno,
           dept.dname
      from emp,
           dept
    where dept.deptno = emp.deptno
    order by empno;
    Regards,
    Zlatko

  • Help : How to use list of values in Variable in ODI

    Dear All,
    I have a multiple values in table, and I would to use these values a a parameter in ODI to retrieve rows based on these values. As I know that we can use single value in variable in ODI.
    Any one can Help me please?

    Can't you use a join between the tables ?
    ODI mostly take advantage of native technologies.
    i.e If my source technology is oracle then i will create a join between the table i.e. MAINTABLE.column = LOVTABLE.COLUMN and also put a filter on LOVTABLE to take required values.
    OR you can write a subquery in the Filter i.e. MAINTABLE.COLUMN in ( Select LOVVALUES from LOVTABLE where LOVTABLE.ATTRIBUTE = 'BUSINESS_UNIT')

Maybe you are looking for

  • No entry in table T555E

    Hi Guy's, While running time evaluation i getting an error that no entry in table T555E for the key 02115 . Plz suggest how to rectify the issue.... Thanks in advance..

  • Managed Server is Not coming UP from STARTING state

    Managed Server is Not coming UP from STARTING state

  • Windows 8 not auto-savin​g data to Excel

    I have written my Labview program on a computer running Windows 7, Labview 2012. The program has two options to save a file to Excel. One option is pushing "Save" on the front panel. The other uses a timer to automatically save the file after a set t

  • Missing Records from SMQ1/RSA7

    Hi Everyone, During the upgrade of BI system, the SMQ1/RSA7 did not clean, which lead to missing of records for only one day from queue. But now the BI system is extracting regular data apart from that day. Can you please help me, how we can get the

  • Workflow: Execute WorkItem from Inbox

    Dear experts We upgraded CRM 4.0 to CRM 2007. We have workflows scenarios in our system. Workflows are received in our Outlook Inbox. From there, we have 3 options: - Workflow Inbox - Display Work Item - Execute Work Item The workitem should open a s