Adding Sales totals from two tables

I have a complicated issue.  I have two sales tables.  Call Table 1 Active_Sales and Table 2 Closed Sales.  I need to total the qty sold fields from both and calculate the revenue from both.  Sales in the Active Sales are stored until a drawer closes for the day and then the sales move to the closed Sales table.  All info is really the same in the two tables, but I need to do active NOW type reporting.  So, how do I take table1.qtysold + table2.qty sold and sum them together for each item sold?
I hope this is enough to go on.

Edison,
You could UNION the 2 tables together in a stored procedure or command object resulting in one field in Crystal that could be summarized.
Or you could create a main report off of 1 table and a subreport off of the other. You could then summarize the sales field in the subreport and pass that value back via a shared variable to the main report.

Similar Messages

  • Adding Sum Totals from Multiple Tables in A single Document

    Hello All,
    I'm having trouble adding sum totals from multiple tables I've created in a Pages 09 doc. I putting together a spreadsheet for cost projections for a house remodel. I created tables for each room of the house. At the bottom of the document I'd like to have another table that takes the totals from each individual room and adds them up. Problem appears to be that each table has the same x/y axis labels so row and column numbers/letters are repeated so the final table can't quantify thing correctly.
    Any easy solutions? I can't find anything that's helped in my search efforts.
    Thanks,
    Josefis

    Jerry,
    Thanks for the feedback. I thought that might be the case. And you were correct to assume I was more comfortable in Pages. I'm halfway through converting everything to numbers. In the end it will work great too. Just some different formatting/design choices to be made as numbers doesn't appear to be as versatile in the same way pages is with design. So far it looks pretty good though.
    Thanks again,
    Josefis

  • ALV OOps report- getting data from two tables and adding issue

    Hi,
    This is sales employee performance report.
    I need to select all the fields from two tables based on user input ie VKorg, sales employee .
    There is one field callled " Net sales"in both the tables.
    Based on sales employee number, i need to add that net sales which i get from two tables.
    I need to generate single report.
    Can you give some inputs reg. the select query.
    My idea is select all the data from both tables using join statement.
    Thanks

    Hi,
    I have written like this:
    select * from S002 as a join S006 as b
        into table ME->SS002_RAW[]
        where vkorg in me->select_parameters->SO_VKORG[] = vkorg in me->select_parameters->SO_VKORG[]
              and ZZSLSEMP01 in me->select_parameters->SO_so_empl[] = ZZSLSEMP02 in me->select_parameters->SO_so_empl[].
    when i do like that,
    I am getting error
    Incorrect structure of FROM clause . . . .     
    If you give some idea on this
    Edited by: Raja on Apr 22, 2009 11:19 AM

  • XML generation from two tables

    Hi,
    I need to write an Oracle SP(Id as input) create an XML strucutre out of the records fetched from two tables. There is no Fk relation between the tables.
    Table A ---> has one record per interface per id
    Table B---> has multiple records per interface per id
    Table A
    1) Id
    2)ErrorCount
    3)SuccessCount
    4)Total
    5)InterfaceName
    Table B
    1)Id
    2)InterfaceName
    3)ErrorDetail
    4)ErrorMessage
    XML Strucutre
    <Report>
    <TableA>
    <Id>
    <InterfaceName>
    <Success/>
    <Total/>
    </InterfaceName>
    </Id>
    </TableA>
    <TableB>
    <Id>
    <InterfaceName>
    <ErrorDetail/>
    <ErrorMesage/>
    </InterfaceName>
    </Id>
    </TableB>
    </Report>
    Thanks,
    Is
    Edited by: Is916 on Sep 16, 2009 2:27 AM

    There are several ways to general XML.
    Here's just one...
    with A as (select 1 as id, 2 as errorcount, 4 as successcount, 6 as total, 'Bob' as interfacename from dual union all
               select 2, 1, 4, 5, 'Fred' from dual)
        ,B as (select 1 as id, 'Bob' as interfacename, 'Error 1' as errordetail, 'Ouch that hurt' as errormessage from dual union all
               select 1 as id, 'Bob', 'Error 2', 'Why did this happen' from dual union all
               select 2, 'Fred', 'Warning', 'Why worry about it' from dual)
    select xmlelement("Report",
                      A.xml, B.xml
                     ) as xml
    from (select xmlelement("TableA",
                   xmlelement("Id",
                     xmlelement("Success", successcount),
                     xmlelement("Total", total)
                           ) as xml
          from A where A.id = 1) A
        ,(select xmlagg(xmlelement("TableB",
                          xmlelement("Id",
                            xmlelement("InterfaceName",
                              xmlelement("ErrorDetail", errordetail),
                              xmlelement("ErrorMessage", errormessage)
                        ) as xml
          from B where B.id = 1) B
    <Report>
      <TableA>
        <Id>
          <Success>4</Success>
          <Total>6</Total>
        </Id>
      </TableA>
      <TableB>
        <Id>
          <InterfaceName>
            <ErrorDetail>Error 1</ErrorDetail>
            <ErrorMessage>Ouch that hurt</ErrorMessage>
          </InterfaceName>
        </Id>
      </TableB>
      <TableB>
        <Id>
          <InterfaceName>
            <ErrorDetail>Error2</ErrorDetail>
            <ErrorMessage>Why did this happen</ErrorMessage>
          </InterfaceName>
        </Id>
      </TableB>
    </Report>

  • Create a procedure which requires displaying information from two tables

    What if we want to create a procedure which requires displaying information from two tables. In this situation,
    I need to display all the details of an employee from an 'emp' table based on the deptno. and also their salary information which is
    stored in "Salgrade" Table. Is the use of "And" the correct way of using it?
    Do I need to declare all the attributes before begin or I can just access them directly? Thanks
    Create Procedure findDept
    ( I_deptno IN number
    ) As
    Begin
    Select Ename, Job, MGR, Hiredate, Sal, Comm, Dept_no from emp and exp, grade , location from salgrade where dept_no
    = I_Deptno;
    Exception
    When NO_Data_Found then
    DBMS_Output.Put_Line(' Department not found"|| I_deptno);
    End findDept;

    Hi,
    Besides Qwerty's remark, you've also got a quoting error:
    Change
    DBMS_Output.Put_Line(' Department not found"|| I_deptno);
    {code}
    into
    {code}
    dbms_output.put_line(' Department not found: '|| i_deptno);
    {code}
    Which leads to the question:
    What do you want to do when a record is found?
    Display it?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Aggregate from two tables

    Dear all,
    I have a need to compare totals from 2 tables.
    The table data is as follows :
    create table FLIGHTS( PSGRNAME VARCHAR2(64), FLTNBR VARCHAR2(5),
    FLTDATE DATE, NBRINPARTY NUMBER ) ;
    insert into FLIGHTS (PSGRNAME, FLTNBR, FLTDATE, NBRINPARTY)
    values ('SMITH/AMR/BMRS', '001', to_date('20-10-2010', 'dd-mm-yyyy'), 2);
    insert into FLIGHTS (PSGRNAME, FLTNBR, FLTDATE, NBRINPARTY)
    values ('BROWN/CMR', '003', to_date('20-10-2010', 'dd-mm-yyyy'), 1);
    insert into FLIGHTS (PSGRNAME, FLTNBR, FLTDATE, NBRINPARTY)
    values ('GREEN/AMR/BMRS/CMISS', '001', to_date('20-10-2010', 'dd-mm-yyyy'), 3);
    insert into FLIGHTS (PSGRNAME, FLTNBR, FLTDATE, NBRINPARTY)
    values ('DOE', '002', to_date('20-10-2010', 'dd-mm-yyyy'), 1);
    insert into FLIGHTS (PSGRNAME, FLTNBR, FLTDATE, NBRINPARTY)
    values ('MILLER/DMR/CMISS', '002', to_date('20-10-2010', 'dd-mm-yyyy'), 2);
    insert into FLIGHTS (PSGRNAME, FLTNBR, FLTDATE, NBRINPARTY)
    values ('TAYLOR/RMR/TMRS/AMSTR/BMSTR', '002', to_date('20-10-2010', 'dd-mm-yyyy'), 4);
    create table MEALS ( PSGRNAME VARCHAR2(64), FLTNBR VARCHAR2(5),
    FLTDATE DATE, MEALTYPE VARCHAR2(4), NBRINPARTY NUMBER ) ;
    insert into MEALS (PSGRNAME, FLTNBR, FLTDATE, MEALTYPE, NBRINPARTY)
    values ('SMITH/AMR', '001', to_date('20-10-2010', 'dd-mm-yyyy'), 'VGML', 1);
    insert into MEALS (PSGRNAME, FLTNBR, FLTDATE, MEALTYPE, NBRINPARTY)
    values ('BROWN/CMR', '001', to_date('20-10-2010', 'dd-mm-yyyy'), 'SFML', 1);
    insert into MEALS (PSGRNAME, FLTNBR, FLTDATE, MEALTYPE, NBRINPARTY)
    values ('TAYLOR/BMSTR', '002', to_date('20-10-2010', 'dd-mm-yyyy'), 'CHML', 1);
    I need to compare the total bookings against count of people who had a meal request. The result would look like this
    FLTDATE FLTNBR PSGR_COUNT MEAL_COUNT
    10/20/2010 001 5 2
    10/20/2010 002 7 1
    10/20/2010 003 1 0
    I tried searching the forum and internet in general and found this : http://www.dba-oracle.com/t_convert_set_to_join_sql_parameter.htm
    However, I could not understand the article fully. Hope someone here can help me here with an example query which I can translate to the real data.
    Oracle version is 10g.
    Both tables contain around 10 million or more records.
    Regards
    Crusoe
    Edited by: Crusoe on Oct 21, 2010 1:57 PM

    Hi,
    Where Mustafa used COUNT (*), just use SUM (nbrinparty) instead.
    Also, you need to GROUP BY both fltnbr and fltdate, and join by both columns as well.
    Since there can be flights with no meals (like fltnbr 003), the join has to be an outer join.
    So what you want is something like:
    SELECT      f.fltdate
    ,      f.fltnbr
    ,      flight_total
    ,      NVL (meal_total, 0)     AS meal_total
    FROM       (
              SELECT        fltdate,  fltnbr
              ,       SUM (nbrinparty)      AS meal_total
              FROM       meals
              GROUP BY  fltdate,  fltnbr
         ) m
              SELECT       fltdate,  fltnbr
              ,       SUM (nbrinparty)      AS flight_total
              FROM       flights
              GROUP BY  fltdate,  fltnbr
         ) f
    WHERE     m.fltdate (+)      = f.fltdate
    AND     m.fltnbr  (+)     = f.fltnbr;Alternatively, you could do just one sub-query, to get the sum from either one of the tables. In the main query, get the sum from the other table and join, like this:
    ITH     got_meal_total     AS
         SELECT        fltdate,  fltnbr
         ,       SUM (nbrinparty)      AS meal_total
         FROM       meals
         GROUP BY  fltdate,  fltnbr
    SELECT      f.fltdate
    ,      f.fltnbr
    ,      SUM (f.nbrinparty)          AS flight_total
    ,      NVL (SUM (m.meal_total), 0)     AS meal_total
    FROM           flights        f
    LEFT OUTER JOIN  got_meal_total      m  ON       f.fltdate     = m.fltdate
                                 AND   f.fltnbr     = m.fltnbr
    GROUP BY  f.fltdate
    ,       f.fltnbr
    ;Edited by: Frank Kulash on Oct 21, 2010 6:52 AM
    Added one-sub-query option

  • To Select the data from two table one is transp table and onther is cluster

    Hi All,
    I want to select the data from two tables
    Here i am giving with an example.
    Fileds: kunnr belnr from bseg.  table bseg
    fields: adrnr from kna1     table: kna1.
    Know i want to put these into one internal table based on kunnr and belnr.
    Thanks in advance.
    Ramesh

    Hi,
       U cant use joins on cluster table and BSEG is a cluster table so use FOR  ALL ENTRIES for taht
    refer this code
    *&      Form  sub_read_bsak
          text
    -->  p1        text
    <--  p2        text
    FORM sub_read_bsak.
    *--Select data from BSAK Table
      SELECT lifnr
             augdt
             augbl
             gjahr
             belnr
             xblnr
             blart
             dmbtr
             mwskz
             mwsts
             sgtxt
             FROM bsak
             INTO CORRESPONDING FIELDS OF TABLE it_bsak
             WHERE belnr IN s_belnr
             AND   augdt IN s_augdt.
      IF sy-subrc EQ 0.
    *--Sort table by accounting document and vendor number
        SORT it_bsak BY belnr lifnr.
      ENDIF.
    ENDFORM.                    " sub_read_bsak
    *&      Form  sub_read_bseg
          text
    -->  p1        text
    <--  p2        text
    FORM sub_read_bseg.
      IF NOT it_bsak[] IS INITIAL.
    *--Select data from BSEG table
        SELECT belnr
               gjahr
               shkzg
               kostl
               hkont
               ebeln
               ebelp
               FROM bseg
               INTO CORRESPONDING FIELDS OF TABLE it_bseg
               FOR ALL ENTRIES IN it_bsak
               WHERE belnr EQ it_bsak-belnr
               AND   gjahr EQ it_bsak-gjahr
               AND   shkzg EQ 'S'.
        IF sy-subrc EQ 0.
    *--Sort table by accounting document
          SORT it_bseg BY belnr.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_read_bseg

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • Select from two tables and insert into a third

    I'm trying to do a select from two tables and do an insert into a third table from the two resulting columns.
    I have the following....
    DECLARE
    tempsid number;
    temphostid number;
    BEGIN
    select "DBSID_ID","ID" into tempsid,temphostid from "DBSIDS","SERVERS"
    where "HOST_SID" like '%'||"DBSID_NAME"||'%'
    and "HOST_NAME" not like 'vio%'
    and exists (select "DBSID_NAME" from DBSIDS)
    order by "DBSID_NAME";
    insert into "DBSID_LOOKUP" ("SIDLOOKUP_ID", "SERVERLOOKUP_ID")
    values(tempsid, temphostsid);
    END;
    run;
    I get the error ....
    ORA-06550: line 11, column 18:
    PL/SQL: ORA-00984: column not allowed here
    ORA-06550: line 10, column 1:
    PL/SQL: SQL Statement ignored
    1. DECLARE
    2. tempsid number;
    3. temphostid number;

    okay ... I tried a different way ...
    DECLARE
    a number;
    b number;
    BEGIN
    select "DBSID_ID","ID" into a,b from "DBSIDS","SERVERS"
    where "HOST_SID" like '%'||"DBSID_NAME"||'%'
    and "HOST_NAME" not like 'vio%'
    and exists (select "DBSID_NAME" from DBSIDS)
    order by "DBSID_NAME";
    insert into "DBSID_LOOKUP" (SIDLOOKUP_ID, SERVERLOOKUP_ID) values (a, b);
    END;
    and now it whines about ...
    ORA-01422: exact fetch returns more than requested number of rows

  • Cartesian of data from two tables with no matching columns

    Hello,
    I was wondering – what’s the best way to create a Cartesian of data from two tables with no matching columns in such a way, so that there will be only a single SQL query generated?
    I am thinking about something like:
    for $COUNTRY in ns0: COUNTRY ()
    for $PROD in ns1:PROD()
    return <Results>
         <COUNTRY> {fn:data($COUNTRY/COUNTRY_NAME)} </COUNTRY>
         <PROD> {fn:data($PROD/PROD_NAME)} </PROD>
    </Results>
    And the expected result is combination of all COUNTRY_NAMEs with all PROD_NAMEs.
    What I’ve noticed when checking query plan is that DSP will execute two queries to have the results – one for COUNTRY_NAME and another one for PROD_NAME. Which in general results in not the best performance ;-)
    What I’ve noticed also is that when I add something like:
    where COUNTRY_NAME != PROD_NAME
    everything is ok and there is only one query created (it's red in the Query plan, but still it's ok from my pov). Still it looks to me more like a workaround, not a real best approach. I may be wrong though...
    So the question is – what’s the suggested approach for such queries?
    Thanks,
    Leszek
    Edited by xnts at 11/19/2007 10:54 AM

    Which in general results in not the best performanceI disagree. Only for two tables with very few rows, would a single sql statement give better performance.
    Suppose there are 10,000 rows in each table - the cross-product will result in 100 million rows. Sounds like a bad idea. For this reason, DSP will not push a cross-product to a database. It will get the rows from each table in separate sql statements (retrieving only 20,000 rows) and then produce the cross-product itself.
    If you want to execute sql with cross-products, you can create a sql-statement based dataservice. I recommend against doing so.

  • Select data from two tables...!

    HI Experts...!
    i m a beginner user and i want to select data from two tables proj and prps.....using joins.....and internal tables i have written a code...
    SELECT prps~pspnr
           prps~objnr
           prps~psphi
           proj~ernam
           proj~erdat
           proj~pspnr
    INTO  table itab   -
    itab is internal table
    FROM prps inner join proj
    WHERE pspnr in p_no and prpspsphi = projpspnr.
    but there is error in from clause ..please help me....
    Advance thanx....

    Hi,
    check the sample code bellow above two reply will solve out your problem but one more extra line in your code pointed out bellow.
    TABLES: prps, proj.
    TYPES:  BEGIN OF ty_test,
            pspnr LIKE prps-pspnr,
            objnr LIKE prps-objnr,
            psphi LIKE prps-psphi,
            ernam LIKE proj-ernam,
            erdat LIKE proj-erdat,
            END OF ty_test.
    DATA: itab TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
    SELECT-OPTIONS: p_no FOR prps-pspnr.
    SELECT  prps~pspnr
            prps~objnr
            prps~psphi
            proj~ernam
            proj~erdat
    *        proj~pspnr " No need for this you have selected this in
    *     the first line because it is commone so you only need to select from any one
            INTO TABLE itab
    FROM prps INNER JOIN proj ON ( prps~pspnr = proj~pspnr  )
    WHERE prps~pspnr IN p_no.
    Best Regards,
    Faisal
    Edited by: Rob Burbank on Dec 24, 2009 12:24 PM

  • Creating a external content type for Read and Update data from two tables in sqlserver using sharepoint designer

    Hi
    how to create a external content type for  Read and Update data from two tables in  sqlserver using sharepoint designer 2010
    i created a bcs service using centraladministration site
    i have two tables in sqlserver
    1)Employee
    -empno
    -firstname
    -lastname
    2)EmpDepartment
    -empno
    -deptno
    -location
    i want to just create a list to display employee details from two tables
    empid firstname deptno location
    and same time update  in two tables
    adil

    When I try to create an external content type based on a view (AdventureWorks2012.vSalesPerson) - I can display the data in an external list.  When I attempt to edit it, I get an error:
    External List fails when attached to a SQL view        
    Sorry, something went wrong
    Failed to update a list item for this external list based on the Entity (External Content Type) 'SalesForce' in EntityNamespace 'http://xxxxxxxx'. Details: The query against the database caused an error.
    I can edit the view in SQL Manager, so it seems strange that it fails.
    Any advice would be greatly GREATLY appreciated. 
    Thanks,
    Randy

  • Retrive data from two tables into one internal table.

    Hi SDN,
    I am downloading the Assets data from two tables ANLA,ANLZ.
    there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
    can you please send me the SELECT Syntax for this probl.....
    Thank you & Regards,
    Manoj

    Hi manoj,
    Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
    data: begin of itab occurs 0,
            BUKRS like anla-BUKRS,
            ANLN1 like anla-ANLN1,
           BDATU like anlz-BDATU,
            end of itab.
    select anlabukrs anlaANLN1 anlzBDATU  into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
    Please come back for any clarification.
    Thanks and Regards,
    saurabh

  • Selecting from two tables and confirming from them despites they not relate

    Please I need a query to select from two tables that are not related to each other.
    I also want to confirm data's as in verify wether what the user has entered is in accordance with what is in the tables
    Examples
    the first table is named "Card" and the second table is named "Student_Details"
    Card table contains a column named "Pin_Number".
    The Student_Details table contains fields such as Exam_Number, Name, Age, Sex.
    The user has to Enter the Pin_Number which has to be confirmed in the Card table and Exam_Number which has to be confirmed in the Student_Details table and verify that both data's are correct.
    Please I need the SQL and PL/SQL queries for this problem.
    Thanks

    Hi,
    I think you need two different queries
    You can write a procedure like:
    create or replace procedure p1 (p_pin_number number, p_exam_number)
    is
      r_card_row            card%rowtype;
      r_student_details     student_details%rowtype;
      cursor c1 is
      select *
        from card
       where pin_number = p_pin_number;
      cursor c2 is
      select *
        from student_details
       where exam_number = p_exam_number;
    begin
      open c1;
        loop
          fetch c1 into  r_card_row;
          exit when c1%notfound;
          ....  do whatever you want..... and the samething you can do with other cursor
        end loop;
      close c1;
    end p1;Hope this helps
    Ghulam

  • Selecting from two tables but making it just one selection

    Is there a way to select from two tables and just have one selection appear?
    Specifically I have a fact_install_unit, and a fact_install_arch table.
    Sometimes the value exists in fact_install_unit.factory_timestamp, and sometimes when fact_install_unit.factory_timestamp is null I need to pull it from the fact_install_arch.factory_timestamp.
    sort of like:
    (select fact_install_unit.factory_timestamp
    from fact_install_unit, fact_install_arch
    where fact_install_unit.fl_unit_sak = fact_install_arch.fl_unit_sak
    and where fact_install_unit.factory_timestamp is null then display fact_install_arch.factory_timestamp)

    > I was just stating that I do not have sufficient priveleges to create views in this database.
    >
    nm means "no more" than that
    And how are we supposed to know that? You seem to have changed the thread subject to "unfortunately I only have read-only and insufficient priveleges", which is not even a question.
    nm means "New Mexico":
    http://www.myshortpencil.com/schooltalk/messages/85/515.html?971794944

Maybe you are looking for