How can i use SUM aggregate in select query?

HI,
GURUS,
How can i use SUM function in Select Query and i want to store that value into itab.
for ex:
TABLES: vbap.
types: begin of ty_vbap,
       incluse type vbap,
       sum type string,
      end of ty_vbap.
data: i_vbap type TABLE OF ty_vbap,
      w_vbap type ty_vbap.
SELECT sum(posnr) FROM vbap into table i_vbap up to 5 rows.
                        (or)
SELECT sum(posnr) FROM vbap into table i_vbap group by vbeln.
  loop at i_vbap into w_vbap
" which variable have to use to display summed value.
  endloop.
if above code is not understandable pleas give ome sample code on  above query.
Thank u,
shabeer ahmed.

Hi,
Check this sample code.
TABLES SBOOK.
DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
DATA:  CONNID LIKE SBOOK-CONNID.
SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
       INTO (CONNID, COUNT, SUM, AVG)
       FROM SBOOK
       WHERE
         CARRID   = 'LH '      AND
         FLDATE   = '19950228'
       GROUP BY CONNID.
  WRITE: / CONNID, COUNT, SUM, AVG.
ENDSELECT.
Regards,
Sravanthi

Similar Messages

  • How can i use param in my select query ( see code)

    Hi ,
    I need to use the param instead of hardcoding the value in the select query , when i did that it is working .
    I think the limit of args is only till the end of main and my select query is in a method called Load() .
    How can i use the param in my select query .
    public static void main(String[] args){
    name = args[0];
    class= args[1];
    new Load();
    }//end of main
    public Load()
              try {
                   Class.forName(JDBC_DRIVER);
                   connection = DriverManager.getConnection(DATABASE_URL,"username","pw");
                   statement = connection.createStatement();
                   //First Query : pin and ticket number
                   ResultSet resultSet = statement.executeQuery("SELECT pin , ticketnumber from airport ,year where "+                                                                      "year.year_name= Here i need to use the param (instead of hardcoding) and year.class_year= Here too i need to use param");
    }// end of method Load()Edited by: 1sai on Sep 24, 2008 7:34 AM
    Edited by: 1sai on Sep 24, 2008 7:35 AM

    Might I suggest you change the structure of your program to the following:
    public class Load {
      private Connection conn;
      private PreparedStatement statement;
      public Load(String sql) {
        init(sql);
      protected void init(String sql) throws Exception {
        Class.forName(JDBC_DRIVER);
        conn = DriverManager.getConnection(DATABASE_URL, "username", "pw");
        statement = conn.prepareStatement(sql);
      public ResultSet execute(String p1, String p2) throws Exception {
        statement.setString(1, p1);
        statement.setString(2, p2);
        return statement.executeQuery();
      public void close() throws Exception {
        if (statement != null)
          statement.close();
        statement = null;
        if (conn != null)
          conn.close();
        conn = null;
      public static void main(String[] args) throws Exception {
        String sql = args[0];
        String param1 = args[1];
        String param2 = args[2];
        Load load = new Load(sql);
        ResultSet rs = load.execute(param1, param2);
        while (rs.next())
          System.out.println(rs.get(0));
        rs.close();
        load.close();
    }This allows you to use the same "Load" object for multiple queries with different parameters.
    I do not recommend you actually use the code above in any sort of production application. You should really take a look at Spring Framework along with an ORM tool like Hibernate or Ibatis to simplify your DAO layer.
    Hope this helps,
    David

  • How can I use a where in Select clause?

    How can I use a where in select clasue when the other part of the where I do not not.
    I mean that
    Select *
    from mara
    where MATNR = MT*
    That means it can have MTA, MTB, MTC....and so on
    I can I write this code.
    Regards,
    Subhasish

    hiii
    you can use following query
    SELECT * FORM mara WHERE matnr CONTAINING 'MT'
    or use following
    select * from mara WHERE matnr =  'MT%'
    reward if useful
    thx
    twinkal

  • How can we use list box on selection screen

    hi, howe can we use list box on selection screen and how can we populate the dat ainto the list box and how can we retrive data based on list box from ther database.
    thanks in advance
    raju

    Use the VRM_SET_VALUES function module.
    DATA: list              TYPE vrm_values,
          value             LIKE LINE OF list.
               AT SELECTION SCREEN OUTPUT
    AT SELECTION-SCREEN OUTPUT.
      name = 'P_OBJECT'.
      CLEAR list.
      REFRESH list.
      CLEAR value.
      value-key = '1'.
      value-text = 'Development Class'.
      APPEND value TO list.
      CLEAR value.
      value-key = '2'.
      value-text = 'Program'.
      APPEND value TO list.
      CLEAR value.
      value-key = '3'.
      value-text = 'Function Module'.
      APPEND value TO list.
      CLEAR value.
      value-key = '4'.
      value-text = 'Database Table'.
      APPEND value TO list.
      CLEAR value.
      value-key = '5'.
      value-text = 'Structure'.
      APPEND value TO list.
      CLEAR value.
      value-key = '6'.
      value-text = 'View'.
      APPEND value TO list.
      CLEAR value.
      value-key = '7'.
      value-text = 'Data Element'.
      APPEND value TO list.
      CLEAR value.
      value-key = '8'.
      value-text = 'Table Type'.
      APPEND value TO list.
      CLEAR value.
      value-key = '9'.
      value-text = 'Class / Interface'.
      APPEND value TO list.
      CLEAR value.
      value-key = '10'.
      value-text = 'Type Group'.
      APPEND value TO list.
      CLEAR value.
      value-key = '11'.
      value-text = 'Domain'.
      APPEND value TO list.
      CLEAR value.
      value-key = '12'.
      value-text = 'Search Help'.
      APPEND value TO list.
      CLEAR value.
      value-key = '13'.
      value-text = 'Lock Object'.
      APPEND value TO list.
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id              = name
          values          = list
        EXCEPTIONS
          id_illegal_name = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.

  • How can I use lead/lag in this query

    I have written this query which gives me the comparative data based on this week and next week. How can I use Lead/Lag in this query.
       WITH CURRENT_WEEK
              AS (  SELECT   QPAQ.YEAR YEAR,
                             QPAQ.SEASON SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
                             TO_NUMBER (QPAQ.WEEK) WEEK,
                             MAX (QPAQ.FAILURES) FAILURES
                      FROM   QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
                     WHERE       QPTL.CATEGORY_ID = 7
                             AND QPAQ.YEAR = QPTL.YEAR
                             AND QPAQ.SEASON = QPTL.SEASON
                             AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
                  GROUP BY   QPAQ.YEAR,
                             QPAQ.SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
                             TO_NUMBER (QPAQ.WEEK)
                  ORDER BY   REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+')),
           LAST_WEEK
              AS (  SELECT   QPAQ.YEAR YEAR,
                             QPAQ.SEASON SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
                             TO_NUMBER (QPAQ.WEEK + 1) WEEK,
                             MAX (QPAQ.FAILURES) FAILURES
                      FROM   QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
                     WHERE       QPTL.CATEGORY_ID = 7
                             AND QPAQ.YEAR = QPTL.YEAR
                             AND QPAQ.SEASON = QPTL.SEASON
                             AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
                  GROUP BY   QPAQ.YEAR,
                             QPAQ.SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
                             TO_NUMBER (QPAQ.WEEK)
                  ORDER BY   REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'))
         SELECT   CURRENT_WEEK.YEAR,
                  CURRENT_WEEK.SEASON,
                  CURRENT_WEEK.ACC_SERIES,
                  CURRENT_WEEK.WEEK,
                  CURRENT_WEEK.FAILURES,
                  (CURRENT_WEEK.FAILURES - LAST_WEEK.FAILURES) FAILURES_COMPARE
           FROM   LAST_WEEK, CURRENT_WEEK
          WHERE   CURRENT_WEEK.WEEK = LAST_WEEK.WEEK(+)
       ORDER BY   CURRENT_WEEK.WEEK;Output is like this.
                    YEAR         SEASON     MODEL                     WEEK        FAILURES    Failures_COMPARE
    1     2011     SUMMER     VGP-BMS15     49     10     
    2     2011     SUMMER     VGP-BMS15     50     28       18
    3     2011     SUMMER     VGP-BMS15     51     30       2
    4     2011     SUMMER     VGP-BMS15     52     40       10Edited by: BluShadow on 06-Jan-2012 13:26
    added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You would jettison the entire LAST_WEEK subquery. Then replace your failure calculation with
        current_week.failure - lag(current_week.failure) over (order by current_week.year, current_week.week) as failures_compareI suppose you might want to think about renaming the sub-query as well ....
    Cheers, APC
    Edited by: APC on Jan 6, 2012 1:41 PM

  • How can I use the Rownum/Customized SQL query in a Mapping?

    Hi,
    * I need to use a Rownum for populating one of the target field? How to create a mapping with Rownum?
    * How can I use an Dual table in OWB mapping?
    * Can I write Customized SQL query in OWB? How can I achieve this in a Mapping?
    Thanks in Advance
    Kishan

    Hi Niels,
    As I'm sure you know, the conundrum is that Reports doesn't know how many total pages there will be in the report until it is all done formatting, which is too late for your needs. So, one classical solution to this problem is to run the report twice, storing the total number of pages in the database using a format trigger, and throwing away the output from the first run when you don't know the total number of pages.
    Alternatively, you could define a report layout so that the number of pages in the output is completely predictable based upon, say, the number of rows in the main query. E.g., set a limit of one, two, ... rows per page, and then you'll know how many pages there will be simply because you can count the rows in a separate query.
    Hope this helps...
    regards,
    Stewart

  • How can I use SUM function to calculate # of employees in the comp.&deptnt?

    I've got two tables: employee & department. I am trying to calculate total employees by department and total employees by the entire company. I know I need to use SUM function, but I only can calculate total employees by department & by company separately. I need to get this output:
    DEPT_NAME     DEPT_TOTAL_SALARY         COMPANY_TOTAL_SALARY
    RESEARCH                  10875                        29025
    SALES                      9400                        29025   
    ACCOUNTING                 8750                        29025     
    This is my code:
    SELECT department_name, SUM(salary) as total_salary
    FROM employee, department
    WHERE employee.department_id = department.department_id
    GROUP BY department_name;
    SELECT SUM(salary)
    FROM employee;
    Can somebody help please?
    Thank you in advance.Edited by: user13675672 on Jan 30, 2011 2:29 PM
    Edited by: user13675672 on Jan 30, 2011 2:31 PM

    Hi, Peter
    Peter Gjelstrup wrote:
    ... There might be a smarter way, with no re-select.You're right, as usual.
    SELECT       d.dname
    ,       SUM (e.sal)               AS dept_tot_sal
    ,       SUM (SUM (e.sal)) OVER ()     AS comp_tot_sal
    FROM       scott.dept     d
    JOIN       scott.emp     e  ON     d.deptno     = e.deptno
    GROUP BY  d.dname
    ;Analytic functions are computed after aggregate functions, so an aggregate function can be nested inside an analytic function.
    Another way (without a sub-query, at least) would be SELECT DISTINCT, with only analytic functions.
    SELECT DISTINCT
           d.dname
    ,       SUM (e.sal) OVER (PARTITION BY  d.dname)     AS dept_tot_sal
    ,       SUM (e.sal) OVER ()                    AS comp_tot_sal
    FROM       scott.dept     d
    JOIN       scott.emp     e  ON     d.deptno     = e.deptno
    ;

  • Sample XML format that can be used to write a SELECT query

    Hello,
    I want to use and XML file in the scenario FILE to JDBC where i use the operation as SELECT in which i want to embbed an sql statemnet which is equivalent to
    SELECT EMPNO, NAME FROM EMPLOYEE WHERE EMPNO>1
    as in the form of XML format like,
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
    <STATEMENT>
    <TABLENAME ACTION="SELECT">
    <TABLE>EMPTEST</TABLE>
    <ACCESS>
    <EMPNO></EMPNO>
    <NAME></NAME>
    </ACCESS>
    <KEY>
    <EMPNO compareOperation="GT">1</EMPNO>
    </KEY>
    </TABLENAME>
    </STATEMENT>
    </ns0:MT_JDBC_SELECT_JDBC_REQ>
    Can i do like this?
    PLease help me out in using various conditions in the XML file formats like the above.
    Thanks,
    Soorya.

    Hello raj,
    I would like to write the query in that format where i mentioned as,
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
    <STATEMENT>
    <TABLENAME ACTION="SELECT">
    <TABLE>EMPTEST</TABLE>
    <ACCESS>
    <EMPNO></EMPNO>
    <NAME></NAME>
    </ACCESS>
    <KEY>
    <EMPNO compareOperation="GT">1</EMPNO>
    </KEY>
    </TABLENAME>
    </STATEMENT>
    </ns0:MT_JDBC_SELECT_JDBC_REQ>
    without giving clear SQL statement as you mentioned here like,
    <ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
    <STATEMENT>
    <TABLENAME ACTION="SQL_QUERY">
    <ACCESS>SELECT EMPNO, NAME FROM EMPLOYEE WHERE EMPNO > '$EMPNO$’</ACCESS>
    <KEY>
    <EMPNO>1</EMPNO>
    </KEY>
    </TABLENAME>
    </STATEMENT>
    </ns0:MT_JDBC_SELECT_JDBC_REQ>
    Thanks,
    Soorya

  • How can replace IF condition for a Select query in my reports?

    IF s_bukrs-LOW = '4312' OR s_bukrs-LOW = '4313' OR s_bukrs-LOW = '4349'  .
    ELSEIF s_bukrs-LOW = '4310' OR s_bukrs-LOW = '4311' OR s_bukrs-LOW = '4587'.
    ENDIF.
    What if I want to use select query in place of IF condition, in my report for a Z -table in which I have made entries of ZZUSEREXIT-my progam name ,VAR1-4310,VAR2-4311,VAR3-4312,VAR4-4313,VAR5-4349,VAR6-4587?

    HI
    U can do this by two ways-
    (1) Using Two SELECT statementsie. one for IF statements and second for ELSEIF statements.
    Like--
        SELECT < field name>,
    WHERE s_bukrs-LOW = '4312' OR s_bukrs-LOW = '4313' OR s_bukrs-LOW = '4349' 
    SELECT < field name>,
    WHERE s_bukrs-LOW = '4310' OR s_bukrs-LOW = '4311' OR s_bukrs-LOW = '4587'.
    (2) U can do this in using IF with select statements.
    This will help u

  • How can I use a variable in webi query filter

    I created a webi report using the fiscal year/month(period) field as a filter to show a window of 18 periods.  The report works just as requested using a between filter on fiscal period with prompts for both the start and ending periods.  Now I'd like to calculate the start period based on what was entered in the prompt for the ending period (e.g. enter 201106 for the TO prompt on the between statement and have the FROM statement filled in as 201001.)  I can create variables in the report to display both the user response to the ending period prompt and the calculated starting period, but I cannot figure out how to incorporate that calculated starting date into the FROM side of the between query filter.
    Any suggestions? 
    Thanks,
    Doug
    Sorry I got my froms and to's mixed up in the first draft. Edited by: Doug Roswold on Mar 4, 2011 6:27 PM

    Let me understand what you want to do.  You don't want to use two prompts, just one, insn't it?
    I mean, instead of:
    Filter area:
    Date between "From prompt" to "To Prompt"
    You want something like:.
    Filter area:
    Date between Variable  to "To Prompt"
    if I'm not wrong that's not possible to achieve in Webi Query  Panel.
    Can you modify your universe? The only way to achieve it is modifying your universe, creating your formula in the universe and assigning it to an object, so you can use this new object in your filter area like this:
    Date between MyUniverseObject  to "To Prompt"
    Edited by: PadawanGirl on Mar 4, 2011 8:15 PM

  • Can not use SUM in a simple query because of a syntax error?

    Hi
    Thank you for reading my post.
    I am trying to execute the following query:
    q = em.createQuery("SELECT SUM((NE.pipeLength - 0.6)+((NE.networkDepth-NE.initialDepth)*0.41)+ NE.standLenght)  FROM NExpansion NE  where (( NE.contract.contractor=:contractor) AND (NE.pDiameter=:diameter))");
                  q.setParameter("contractor", contractor);
    q.setParameter("diameter", diameter);
         l =  (Long) q.getSingleResult();And I get the following error:
    Caused by: Exception [TOPLINK-8025] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException
    Exception Description: Syntax error parsing the query [SELECT SUM((NE.pipeLength - 0.6)+((NE.networkDepth-NE.initialDepth)*0.41)+ NE.standLenght)  FROM NExpansion NE  where (( NE.contract.contractor=:contractor) AND (NE.pDiameter=:diameter))], line 1, column 12: unexpected token [(].
    Internal Exception: line 1:12: unexpected token: (
            at oracle.toplink.essentials.exceptions.EJBQLException.unexpectedToken(EJBQLException.java:389)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.handleANTLRException(EJBQLParser.java:350)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.addError(EJBQLParser.java:278)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.reportError(EJBQLParser.java:378)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.aggregateExpression(EJBQLParser.java:1416)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectExpression(EJBQLParser.java:1158)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectClause(EJBQLParser.java:403)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectStatement(EJBQLParser.java:178)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.document(EJBQLParser.java:135)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.parse(EJBQLParser.java:166)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParseTree(EJBQLParser.java:127)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:215)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:189)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:153)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:114)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:99)
            at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
            at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:204)
            ... 30 more
    Caused by: line 1:12: unexpected token: (
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.aggregateExpression(EJBQLParser.java:1365)
            ... 43 morePlease let me know what am I doing wrong?
    Thanks.

    Hello,
    From the grammar in the JPA spec, SUM only takes a state_field_path_expression which is defined as
    state_field_path_expression := {identification_variable | single_valued_association_path_expression}.state_field
    Please feel free to file an enhancement to have this expanded upon.
    Best Regards,
    Chris

  • How can i use Order by inside a sub query in Oracle

    Hi!,
    Please help me, it's an urgent... how can i use Order by clause
    SELECT SalesProductKeyID,ActualUnitPrice,BillDateKeyID,ProductKeyID
    ,Qty,Profit,DD.dDate
    , (SELECT nvl(S.Qty,0) FROM Stock S , DateDimension DD1
    WHERE S.DateKeyID = DD1.DateKeyID AND
    S.ProductKeyID = SF.ProductKeyID AND
    DD1.dDate <= DD.dDate and rownum=1
    ORDER BY DD1.dDate DESC*) as StockQty
    , (SELECT nvl(SUM(Qty),0) from salesfact SF2,DATEDIMENSION DD2
    WHERE SF2.BillDateKeyID=DD2.DatekeyID AND SF2.ProductKeyID=SF.ProductKeyid
    AND DD2.dDate > DD.dDate
    AND DD2.dDATE=DD.dDate
    ) as TotalQtySold
    FROM SalesFact SF INNER JOIN DATEDIMENSION DD
    ON SF.billdatekeyid =DD.Datekeyid
    WHERE
    IsProfitCalculated = 1 AND
    IsSalesFactSuppPopulated =0 AND
    Qty > 0;
    kindly help
    Thank you.

    Actually I'm converting Procedures from SQL Server to Oracle.
    Actual Stored Procedure in SQL Server is as follows.
    SELECT --top 10000 
    SalesProductKeyID,ActualUnitPrice,BillDateKeyID,ProductKeyID
    ,Qty,Profit,DD.Date
    , (SELECT TOP 1 ISNULL(S.Qty,0) FROM dbo.Stock S , dbo.DateDimension DD1
    WHERE S.DateKeyID = DD1.DateKeyID AND
    S.ProductKeyID = SF.ProductKeyID AND
    DD1.Date <= DD.Date
    ORDER BY DD1.Date DESC) as StockQty
    , (SELECT ISNULL(SUM(Qty),0) from salesfact SF2,DATEDIMENSION DD2
    WHERE SF2.BillDateKeyID=DD2.DatekeyID AND SF2.ProductKeyID=SF.ProductKeyid
    AND DD2.Date > DD.Date
    AND DD2.DATE=DD.Date
    ) as TotalQtySold
    --INTO TEMP_Salesfact          
    FROM dbo.SalesFact SF INNER JOIN DATEDIMENSION DD
    ON SF.billdatekeyid =DD.Datekeyid
    WHERE
    IsProfitCalculated = 1 AND
    IsSalesFactSuppPopulated =0 AND
    Qty > 0

  • Using DB Links - Improving SELECT query performance

    Hi there,
    I am using dblink in the following query:
    I would like to improve performance of the query by using hints as per described in the link: http://www.experts-exchange.com/Database/Oracle/9.x/Q_23640348.html. However, i am not sure how can i include this in my select query.
    Details are:
    Oracle - 9i Database Terminal Release .8
    DB Link: TCPROD
    Could someone please explain with an example how to use hints to get the query to select data on the remote database and then return the results to the target database?
    Many Thanks.
    SELECT ec.obid AS prObid,
                 ec.b2ProgramName AS program,
                 ec.projectName AS project,
                 ec.wbsID AS prNo,
                 ec.wbsName AS title,
                 ec.revision AS revision,
                 ec.superseded AS revisionSuperseded,
                 ec.lifeCycleState AS lifeCycleState,
                 ec.b2ChangeType AS type,
                 ec.b2Complexity AS subType,
                 ec.r1SsiCode AS ssi,
                 ec.b2disposition as disposition,
                 ec.wbsOriginator AS requestor,
                 ec.wbsAdministrator AS administrator,
                 ec.changepriority as priority,
                 ec.r1tsc as tsc,
                 ec.t1comments as tenixComments,
                 ec.b2securityclass as securityClassification,
                 ec.t1changesafety as safety,
                 ec.t1actionofficer as actionOfficer,
                 ec.t1changereason as changeReason,
                 ec.t1wbsextchangenumber as extChangeNo,
                 ec.creator as creator,
                 to_date(substr(ec.creationdate,
                                0,
                                instr(ec.creationdate, ':', 1, 3) - 1),
                         'YYYY/MM/DD-HH24:MI:SS') as creationdate,
                 to_date(ec.originatorassigndate, 'YYYY/MM/DD') as originatorassigndate,
                 zbd.description as description,
                 zbc.comments as comments
            FROM (SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM awdbt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM mart1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM mpsdt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM nondt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnast1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnlht1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnolt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rzptt1m4.cmPrRpIt@TCPROD

    it's the tablename in the hint, not the column name
    something like
    SELECT ec.obid AS prObid,
                 ec.b2ProgramName AS program,
                 ec.projectName AS project,
                 ec.wbsID AS prNo,
                 ec.wbsName AS title,
                 ec.revision AS revision,
                 ec.superseded AS revisionSuperseded,
                 ec.lifeCycleState AS lifeCycleState,
                 ec.b2ChangeType AS type,
                 ec.b2Complexity AS subType,
                 ec.r1SsiCode AS ssi,
                 ec.b2disposition as disposition,
                 ec.wbsOriginator AS requestor,
                 ec.wbsAdministrator AS administrator,
                 ec.changepriority as priority,
                 ec.r1tsc as tsc,
                 ec.t1comments as tenixComments,
                 ec.b2securityclass as securityClassification,
                 ec.t1changesafety as safety,
                 ec.t1actionofficer as actionOfficer,
                 ec.t1changereason as changeReason,
                 ec.t1wbsextchangenumber as extChangeNo,
                 ec.creator as creator,
                 to_date(substr(ec.creationdate,
                                0,
                                instr(ec.creationdate, ':', 1, 3) - 1),
                         'YYYY/MM/DD-HH24:MI:SS') as creationdate,
                 to_date(ec.originatorassigndate, 'YYYY/MM/DD') as originatorassigndate
            FROM (SELECT /*+ DRIVING_SITE(awdbt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM awdbt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(mart1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM mart1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(mpsdt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM mpsdt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(nondt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM nondt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(rnast1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnast1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(rnlht1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnlht1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(rnolt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnolt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(rzptt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rzptt1m4.cmPrRpIt@TCPROD) ec(not tested, of course)

  • How can i use index in select query.. facing problem with the select query.

    Hi Friends,
    I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
    Here is the query:
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelat LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelatrprctr
        WHERE rldnr  = c_telstra_accounting
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          And rzzlstar in r_lstar                            
          AND rpmax  = c_max_period.
    There are 5 indices present for Table ZTFTELAT.
    Indices of ZTFTELAT:
      Name   Description                                               
      0        Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)                                          
      005    Profit (RCLNT,RPRCTR)
      1        Ledger, company code, account (RLDNR,RBUKRS, RACCT)                                
      2        Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)                           
      3        Account, cost center (RACCT,RCNTR)                                        
      4        RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR                        
      Z01    Activity Type, Account (RZZLSTAR,RACCT)                                        
      Z02    RYEAR-RBUKRS- RZZZBER-RLDNR       
    Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
    Thanks in advance.

    Hi Shiva,
    I am using two more select queries with the same manner ....
    here are the other two select query :
    ***************1************************
    SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelpt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelptrprctr
        WHERE rldnr  = c_telstra_projects
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar             
          AND rpmax  = c_max_period.
    and the second one is
    *************************2************************
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelnt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelntrprctr
        WHERE rldnr  = c_telstra_networks
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar                              
          AND rpmax  = c_max_period.
    for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables.  if i will not use it will delete all the data fetched earlier.
    Thanks on advanced......
    Sourabh

  • How can I use "Free Selection" in Dunning?

    Hi,
    I am trying to generate the Dunning notice for only Customers that have the Dunning Area Code as 01. For that I am using the 'Free Selection". I have selected the Customer master and then the dunning area and didn't checked the Exclude box and then in  "Values" I have mentioned the Dunning Area Code as 01. But, System is not picking it up so what shall I do. Also, I have some questions in mind:
    1) Why there are two sections of 'Values" field?
    2) What is the process or steps to 'Exclude' the data?
    3) How can I use Dunning groups?
    Please Help.
    Thanks in advance...
    Regards
    Nitin

    Thanks done...
    Regards
    Nitin

Maybe you are looking for

  • T530, only projector mode, notebook's display still on

    Hello, I have my T530 attached to docking station with an external display attached to it via display port. Everything is working properly, I can switch between notebook display and external monitor. Only thing that bothers me is when I turn on my no

  • Getting information from SRM !

    Hi Experts, Can anyone help me find the tables which get updated during the below mentioned processes in SRM. 1) In transaction PPOSA_BBP the details of the cost center, delivery address etc. assigned on a position level or org unit level is stored i

  • INSTALLING ORACLE APPS 12X ON VISTA HOME BASIC

    ive been spending too much time struggling to newly install oracle R12x on windows vista home basic on my laptop HP 4GB RAM but in vain. I successfully installed VMWARE but i cant get it launched, the IE fails to start from there i really dont know w

  • Elements 4.0 windows 8.1 compatibility

    Just tried to get into Elements new computer & windows 8.1 update.  Got compatibility message.  Looked around and did not see anything pertaining to this PS version & 8.1 fixes.  Any ideas?  Please not the obvious buying newer version of Elements.

  • Bridge CS6, preference pane black out

    The preferences window in Bridge is mostly blacked out, I have tried un-installing and then re-installing it from my account in the Cloud but it's still the same. I have tried making the main work area etc as white as possible but it doesn't change t