Joining 2 Statements with Numeric Data

Hi All,
I have 2 statements that produce similar data with numerica data that needs to be added together. Union or Union All doesn't work here. How can I do this?
Table 1
Area       Total
SHERIDAN    50
GILLETTE    150
SOMEAREA    60combine with
Table 2
Area       Total
SHERIDAN    40
GILLETTE    20desired result...
Result
Area       Total
SHERIDAN    90
GILLETTE    170
SOMEAREA    60

Hi,
Johnbr (Oracle11G) wrote:
Thanks Frank... this is helpful.. still getting errors.. Help the people who are trying to help you. Please post the complete error message, including line numbers.
is it because My total columns are called Total Open Crew SOs?It's because the total column is called that inside the in-line view, but you're referencing a column called total in the main query. You can call the column whatever you like, but be consistent.
Avoid using double-quotes, if possible. If you really, really want to have a non-standard column name like "Total Open Crew SOs" in the main query, then use double-auotes there, but use standard names inside the subqueries.
Also, ORDER BY clauses in sub-queries are almost always a waste of resources, because the order won't necessarily be preserved in the main query.
SELECT    BI_LMN_SRV_DESC
,        SUM (total)     AS total
FROM        (
           --  The following is one of the original queries
           SELECT
               T1.BI_LMN_SRV_DESC,
               COUNT(T1.BI_SO_NBR) AS total
           FROM
           --  The preceding is one of the original queries
         UNION ALL
           --  The following is the other one of the original queries
           SELECT
               T1.BI_LMN_SRV_DESC,
               COUNT(T1.BI_SO_NBR) AS total
           FROM
           --  The preceding is the other one of the original queries
GROUP BY      T1.BI_LMN_SRV_DESC
ORDER BY      T1.BI_LMN_SRV_DESC     -- This is the only ORDER BY clause you need in the whole query
Also, T1."BI_LMN_SRV_DESC" is what I'm selecting on instead of AreaThat's fine; there's nothing magical about the column name area. Use whatever you like, but use the same thing in the main query and the sub-query. (In this case, you are already being consistent.)

Similar Messages

  • Execute query  run fine with numeric data not give result on string data

    Hi master
    Sir I use under blow code for execute query
    sir when I use numeric data then run fine but when I use character data then not give any result
    with numeric run fine
    DECLARE
         DD VARCHAR2(15);
    BEGIN
         DD:=10;
    set_block_property('emp', default_where, 'where DEPTNO='||DD);
    go_block('emp');
    execute_query;
    set_block_property('emp', default_where, '');
    END;
    With character not give any result
    DECLARE
         DD VARCHAR2(15);
    BEGIN
         DD:='SALESMAN';
    set_block_property('emp', default_where, 'where RTRIM(EMPNO)='||DD);
    go_block('emp');
    execute_query;
    set_block_property('emp', default_where, '');
    END;
    Please give me any idea

    bro it is not working on string format coz of the missing quotes. e.g. 'smith' or smith. so the quoted string will be compared. in set_block_property u have to include extra quotes on the variable. e.g.
    set_block_property('emp',default_where,'where ename='''||:emp.ename||'');
    or with conditional statement
    set_block_property('emp',default_where,'where ename='''||:emp.ename||''' and dname='''||dept.deptno||'');
    there i included two extra qoutes before joining ename and in the an extra quote to complete to string. if u would like to debug at runtime to show if the qouted string condition is proper then assign the where clause to a variable and message it up.
    like
    myvariable:='where ename='''||:emp.ename||'';
    message(myvariable);
    message(myvariable);
    set_block_property('emp',default_where,myvariable);
    after the string is quoted properly the execute query will work fine, also use the function upper or lower to compare strings.
    zaibi.

  • How do I combine text with numerical data in an array?

    I an acquiring analog data in real time, and I am able to create, output, and save the data, but I would like to place comments next to specific measurements. How do I do that in Labview 7.0 Express? I can place numbers at in a column next to my measurements, but i cannot cobine text and numbers into one array to save and read with excel... Thank you!
    theukranian

    theukranian,
    Convert the numeric data to a string before saving it.
    dmourer

  • How do you sort a text field with numeric data in numeric order

    We have a text field (varchar2) that has numeric data. When we sort it the items display as
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    *101*
    12
    Instead of
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    12
    101
    How can I make it display in numeric order if the field is a varchar2
    Howard

    To avoid string-to-number conversion:
    SQL> with t as (
      2  select '1' a from dual union
      3  select '2' a from dual union
      4  select '3' a from dual union
      5  select '4' a from dual union
      6  select '5' a from dual union
      7  select '6' a from dual union
      8  select '7' a from dual union
      9  select '8' a from dual union
    10  select '9' a from dual union
    11  select '10' a from dual union
    12  select '101' a from dual union
    13  select '12' a from dual)
    14  select a from t
    15  order by length(a), a;
    A
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    12
    101
    12 rows selected.Max
    http://oracleitalia.wordpress.com

  • Case Statement with excel data source

    When trying to create a case statement in the RPD I get the following error in answers when selecting from the column.
    Listed is the RPD column select statement CASE EMPHOURS.EMPHOURS_DIM.PAYCODE WHEN 'OT' THEN 'Overtime' END
    Listed is the error I receive in answers:
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: 37000 code: -3100 message: [Microsoft][ODBC Excel Driver] Syntax error (missing operator) in query expression 'case T24.[PAYCODE] when 'OT' then 'Overtime' end'.. [nQSError: 16014] SQL statement preparation failed. (HY000)
    The statement works fine when I use oracle RDBMS as the data source and not excel.
    Regards

    Hi Sophia,
    Could you please edit Database>Features in this there will be a feature "CASE_IF_SUPPORTED" and another CASE related feature which you need to change and check in this features.
    Regards,
    Som

  • Balance sheet and P n L statement  with leagcy data in BI required!!!

    Hi All
    I am having one requirement on 0FIGL_V10 cube for Balance sheet and P n L statement report.
    My client having 3years of old data(Legacy data) other then current year data which is coming from R3.
    Now he wants to see all data in the query level.
    Please suggest how to proceed to meet clients requirement.
    regards,
    prasad

    Hello Prasad,
    Have a look at these links
    [Balance Sheet and Profit and Loss Statement for SAP BW 3.0|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/24ee9190-0201-0010-6da9-e7d70f28970f]
    [How to Calculate Balance Sheet Key Figures Using the BEx Query Designer Cell Editor (NW2004)|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ce496e17-0301-0010-e0b4-b8ca8b4588ac]
    Thanks
    Chandran

  • 0MATERIAL with numeric data

    Hi Experts,
    We are using 0MATERIAL standard infoobject for master data. We have master data coming in flat file/.csv format and loaded into 0MATERIAL. Material codes contain character data as well as numbers. When we load the material codes, which contain just numbers, system is appending leading zeros. How can we avoid this problem?
    Example: Material code 1234, we want to store and display as 1234 but not 000000000000001234.
    I appeciate your answers.

    HI:
    You would have to remove the ALPHA conversion routine that is implemented by default.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9b/f9c18f5a07f0459127e9676ae22a54/frameset.htm
    Thanks for any points you choose to assign (they are the way of saying "thanks" in SDN).
    Best Regards -
    Ron Silberstein
    SAP

  • Outer join with effective date in peoplesoft query

    Hi,
    I'm trying to join two tables using outer join. Both tables are effective dated:
    Dept_Tbl: dept_id, status, effdt
    Tips_Tbl: dept_id, tips_id, effdt
    Not all records in Dept_Tbl are in Tips_Tbl. I need to get all active depts and their most recent tips_id if they have one.
    select a.dept_id, b.tips_id
    from dept_tbl a, tips_tbl b
    where a.status = 'Active'
    and a.effdt =
    (select max(a_ed.effdt) from dept_tbl a_ed
    where a.dept_id = a_ed.dept_id
    and a_ed.effdt <= SYSDATE)
    and b.dept_id(+) = a.dept_id
    and b.effdt =
    (select max(b_ed.effdt) from tips_tbl b_ed
    where b.dept_id = b_ed.dept_id
    and b.tips_id = b_ed.tips_id
    and b_ed.effdt <= SYSDATE)
    The query only returns records that are in both tables.
    Is there a way for outer join to work with effective dates?
    Thanks in advance,
    Reg

    Here is an example of one solution. Note the use of NVL on both sides of the equal sign since both sides could be NULL in the case of the outer join
    with dept_tbl as (select 1 dept_id, SYSDATE effdt FROM DUAL),
         tips_tbl as (select 1 dept_id, NULL effdt FROM DUAL)
    select a.effdt
      from dept_tbl a,
           tips_tbl b
    where b.dept_id(+) = a.dept_id
       and NVL(b.effdt, SYSDATE) = NVL((select max(b_ed.effdt)
                                          from tips_tbl b_ed
                                         where b.dept_id = b_ed.dept_id
                                           and b_ed.effdt <= SYSDATE), SYSDATE);
    EFFDT
    5/7/2007 3:25:00 PM

  • How to get numeric data from a string using t-sql

    Hi All,
    I have a table with 2 columns ID as Int and Message as nvarchar(max)
    Create table Sample
    ID int not null,
    Message nvarchar(max) null,
    CONSTRAINT [PK_ID_Msg] PRIMARY KEY CLUSTERED
    ID asc
    Insert statement:
    INSERT INTO
    Sample (ID, Message)
    VALUES (1, 'X_YRS: 00 ; X_MONS: 18 ; X_DAYS: 000 ; Y_YRS: 00 ; Y_MONS: 16 ; Y_DAYS: 011 ; Z: 1 ; Z_DATE: 09/04/2014
    INSERT INTO Sample (ID, Message) VALUES (2, 'X_YRS: 01 ; X_MONS: 15 ; X_DAYS: 010 ; Y_YRS: 00 ; Y_MONS: 18 ; Y_DAYS: 017
     ; Z: 1
     ; Z_DATE: 06/02/2012')
    Data in the table looks like:
    ID             Message
    1       X_YRS: 00 ; X_MONS: 18 ; X_DAYS: 000 ; Y_YRS: 00 ; Y_MONS: 16 ; Y_DAYS: 011 ; Z: 1 ; Z_DATE: 09/04/2014
    2       X_YRS: 01 ; X_MONS: 15 ; X_DAYS: 010 ; Y_YRS: 00 ; Y_MONS: 18 ; Y_DAYS: 017 ; Z: 1 ; Z_DATE: 06/02/2012
    Need out put as below, just with numeric data:
    ID      X-Column         Y-Column         
    1       00 18 000        00 16 011
    2       01 15 010        00 18 017
    So, please I need t-SQL to get above output.
    Thanks in advance.
    RH
    sql

    ;With CTE
    AS
    SELECT s.ID,RTRIM(LTRIM(STUFF(Val,1,CHARINDEX(':',Val),''))) AS Val,RTRIM(LTRIM(LEFT(Val,CHARINDEX('_',Val+'_')-1))) AS Pattern,
    --ROW_NUMBER() OVER (PARTITION BY LEFT(Val,CHARINDEX('_',Val+'_')-1) ORDER BY RTRIM(LTRIM(STUFF(Val,1,CHARINDEX(':',Val),'')))*1)
    f.ID AS Seq
    FROM Sample s
    CROSS APPLY dbo.ParseValues(s.[Message],';')f
    WHERE ISNUMERIC(RTRIM(LTRIM(STUFF(Val,1,CHARINDEX(':',Val),'')))+'0.0E0')=1
    SELECT ID,
    STUFF((SELECT ' ' + Val FROM CTE WHERE ID = c.ID AND Pattern = 'X' ORDER BY Seq FOR XML PATH('')),1,1,'') AS XCol,
    STUFF((SELECT ' ' + Val FROM CTE WHERE ID = c.ID AND Pattern = 'Y' ORDER BY Seq FOR XML PATH('')),1,1,'') AS YCol,
    STUFF((SELECT ' ' + Val FROM CTE WHERE ID = c.ID AND Pattern = 'Z' ORDER BY Seq FOR XML PATH('')),1,1,'') AS ZCol
    FROM (SELECT DISTINCT ID FROM CTE)c
    ParseValues can be found here
    http://visakhm.blogspot.in/2010/02/parsing-delimited-string.html
    Numeric check logic is as per below
    http://visakhm.blogspot.in/2014/03/checking-for-integer-or-decimal-values.html
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Numeric data is not displayed in BI Publisher 11g report

    Hi,
    I'm using Oracle BI 11g (11.1.1.6.0).
    I'm experiencing a serious issue with numeric data in reports created with Publisher.
    When I define the query in the data model, numeric data gets declared as "integer" (even if it should be "double"). Anyway, when creating the layout all data is correctly shown.
    The issue emerges when I run the report in interactive mode: numeric data is not displayed at all.
    If I run it in HTML mode or other, I get proper results.
    I tried to explicitly CAST numeric data in the query to number(21, 6) but I get no different result.
    Any help or suggestion is warmly welcome.
    Thanks,
    Cristina

    Yes, assuming that you are using the Standalone version, following are some excerpt from user guide.
    10g see Oracle® Business Intelligence Publisher
    Report Designer's Guide
    Release 10.1.3.4
    Part No. E12187-01
    Chapter 6 Building a Data Template
    Supported Column Types
    CLOB (conditionally supported)
    The CLOB must contain text or XML. Data cannot be escaped inside the CLOB column.
    And for 11g see
    Oracle® Fusion Middleware
    Data Modeling Guide for Oracle Business Intelligence Publisher
    Release 11g (11.1.1)
    Part No. E18862-01
    Chapter 3 Creating Data Sets
    Using Data Stored as a Character Large Object (CLOB) in a Data Model
    BI Publisher supports using data stored as a character large object (CLOB) data type in
    your data models. This feature enables you to use XML data generated by a separate
    process and stored in your database as input to a BI Publisher data model.
    Use the Query Builder to retrieve the column in your SQL query, then use the data
    model editor to specify how you want the data structured. When the data model is
    executed, the data engine can structure the data either as:
    • a plain character set within an XML tag name that can be displayed in a report (for
    example, an Item Description)
    • structured XML
    Cheers,
    ND

  • Text file numerical data in columns (spaces between colums) to graph after averaging each 500 columns values.ple​ase help.

    i have a text file with numerical data in three columns,(first i need to skip the few lines of text within the file above the three column of data values)then i need to convert the numerical values above "-999" to zero,then take the average of each 500 values in the first column (second and third colum needs the same operation separately),thus found average values are to be stored into a text file and finally plotted in a graph separately. Please help.Its apart of my project work.
    Solved!
    Go to Solution.
    Attachments:
    data file.txt ‏715 KB

    i have a text file with numerical data in three columns,(first i need to skip the few lines of text within the file above the three column of data values)then i need to convert the numerical values above "-999" to zero,then take the average of each 500 values in the first column (second and third colum needs the same operation separately),thus found average values are to be stored into a text file and finally plotted in a graph separately.
    " i am attaching the code tht i hv done so far, its for reading and plotting the numerical data from text, but its not working :-( "
    Attachments:
    read from text and plot.vi ‏26 KB
    sample input.txt ‏1 KB
    final input to be read and plot.txt ‏345 KB

  • Left outer join 3 tables with where-statement

    Hi folks,
    I hope you can understand (and maybe solve) my problem.
    Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
    The three table structures are the following:
    table 1 (user)   
    user1 | key
    table 2 (detail)  
    key | ID
    table 3 (header)
    ID | user2                 
    ...and I want to achieve the following structure (as example filled with data):
    user | key | ID
    |-----|----
    xy    | a    | 001
    xy    | b    | #
    z     | b     | #
    The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
    1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
    2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
    I tried this coding:
    SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
      LEFT OUTER JOIN table2 AS b ON akey = bkey )
      LEFT OUTER JOIN table3 AS c ON bID = cID )
      WHERE auser1 = cuser2.
    I would really appreciate your help.
    Regards
    MrclSpdl

    IF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
    select dbfields
    into table itab2
    from dbtab
    for all entries in itab
    where dbfield1 = itab-field1.
    This will get you a second internal table with all the corresponding data for the first selection.  You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation).  Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
    Regards,
    Freek

  • Update statement with joining other tables

    Hi ,
    I have two table one is containing xml file , basically i need to read from those xml file then update to another table based on some condition.
    UPDATE TRCB_XBRL_STG_2 STG
    SET PROFIT =
      case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."') is not null
      THEN EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."')
      WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..') IS NOT NULL
      THEN extractValue(XBRL.xbrlfile,'//PROFIT ', 'xmlns:acra=".."')
      ELSE STG.PROFIT
      END,
      SET REVENUE=
      case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..."') is not null
      THEN EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE.', 'xmlns:acra="..."')
      WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..') IS NOT NULL
      THEN extractValue(XBRL.xbrlfile,'//REVENUE', 'xmlns:acra="REVENUE"')
      ELSE STG.REVENUE
      END,
      ... (around 100 columns)
    FROM  TRCB_XBRL xbrl ,TRCB_XBRL_STG_2 STG
    WHERE STG.XBRL_ID = XBRL.XBRL_ID Number of columns are around 100 , please anyone suggest how to use update statement with joining two tables.

    Hi,
    If all the values needed to update a given row of table_x are coming from the same row of table_y (or from the same row of a result set of a query involving any number of tables), then you can do something like this:
    UPDATE  table_x  x
    SET     (col1, col2, col3, ...)
    =     (
             SELECT  NVL (y.col1, x.col1)
             ,         NVL (y.col2, x.col2)
             ,         NVL (y.col3, x.col3)
             FROM    table_y  y
             WHERE   x.pkey   = y.expr
             AND         ...
    WHERE   ...
    ;If the WHERE clause depends on the same row of table_y, then it will probably be simpler and more efficient to use MERGE instead of UPDATE.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • How to avoid data repetation when using select statements with innerjoin

    how to avoid data repetation when using select statements with innerjoin.
    thanks in advance,
    satheesh

    you can use a query like this...
      SELECT DISTINCT
             frg~prc_group1                  "Product Group 1
             frg~prc_group2                  "Product Group 2
             frg~prc_group3                  "Product Group 3
             frg~prc_group4                  "Product Group 4
             frg~prc_group5                  "Product Group 5
             prc~product_id                  "Product ID
             txt~short_text                  "Product Description
    UP TO 10 ROWS
    INTO TABLE l_i_data
    FROM
    Joining CRMM_PR_SALESG and
    COMM_PR_FRG_ROD
    crmm_pr_salesg AS frg
    INNER JOIN comm_pr_frg_rod AS prd
    ON frgfrg_guid = prdfragment_guid
    Joining COMM_PRODUCT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_product AS prc
    ON prdproduct_guid = prcproduct_guid
    Joining COMM_PRSHTEXT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_prshtext AS txt
    ON prdproduct_guid = txtproduct_guid
    WHERE frg~prc_group1 IN r_zprc_group1
       AND frg~prc_group2 IN r_zprc_group2
       AND frg~prc_group3 IN r_zprc_group3
       AND frg~prc_group4 IN r_zprc_group4
       AND frg~prc_group5 IN r_zprc_group5.
    reward it it helps
    Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM

  • Update statement with inner join

    Hello everyone. I am am trying to do an update statement with an inner join. I have found several examples of SQL statements that work with Sql server and mysql but they don't work in Oracle. Does anyone know the proper way in Oracle 10G? I am trying to update all fields in one table from fields in another table.
    for example:
    UPDATE table3
    SET
    TL3.name = TL2.name,
    TL3.status = TL2.status,
    TL3.date = TL2.date
    FROM table3 TL3 JOIN table2 TL2
    ON (TL3.unique_id = TL2.unique_id);
    any help will be appreciated.

    Hi,
    You can also use MERGE, like this:
    MERGE INTO  table3     dst
    USING   (
             SELECT  unique_id
             ,         name
             ,         status
             ,         dt          -- DATE is not a good column name
             FROM    table2
         )          src
    ON     (dst.unique_id     = src.unique_id)
    WHEN MATCHED THEN UPDATE
    SET     dst.name     = src.name
    ,     dst.status     = src.status
    ,     dst.dt          = src.dt
    ;Unlike UPDATE, this lets you avoid essentially doing the same sub-query twice: once in the SET clause and then again in the WHERE clause.
    Like UPDATE, you don't acutally join the table being changed (table3 in this case) to the other table(s); that is, the FROM clause of the suib-query does not include table3.
    Riedelme is right; you'll get better response to SQL questions like this in the SQL and PL/SQL forum:
    PL/SQL

Maybe you are looking for

  • OSB (ALSB) Logging Redirect

    Hi all, how to redirect all the OSB(ALSB) related message logs ( Errors and transport exceptions included ) to a log4j custom file. Now, given this discussion: alsb logging The way to go is, apparently, to 1. create filters at domain level by subsyst

  • Drive Became Slow All Of A Sudden

    I have an Intel iMac core 2 duo with 1 gig of ram. Attached to a USB port on the back of the computer is a Western Digital Mybook USB 2.0 USB hard drive (250 gig). The drive has always performed as expected, but about a month ago the write speed to t

  • I keep getting Server problems when trying to sign into messages

    Hi can anyone help, I have an Imac, and Lion  X 10.7.3, I have downloaded Messages Beta, evertytime I try to register it will not let me, telling me Server Problems try again later? Has anyone come across this? And can anyone help? Thank you.

  • Exporting Recap

    So I've been using FCE successfully for a little while and while Tom answered all my questions in the beginning, I wanted to check in again to make sure I was importing and exporting in the best possible ways. My footage is either shot on my Canon T1

  • Buttons don't change color.

    Hi, In my theme, every button have the background color green and the text gray. But there is a button (Emphasized button) its background color is Blue and the background color on hover is orange although i put its background color green and backgrou