Join the results of a case statement

Hello everyone;

I can't with a query where I use a case statement to create a new column and attempt to reach an additional table on the resulting column.  I am fairly new to this and learn by trial and error, so if you think that it looks a little ugly or ineffective, I won't be offended.  It is used on my interface based on the web of companies, while I am not able to answer some basic questions such as the version of db.

My need to use the case statement is the result of some strange methods and somewhat contradictory in order to link the product subcodes (sku, fcsku, fnsku), to a product code parent (ProdID).  In this case, the inventory is stored in the first table with one of the few types of premises SKUs, however the dimensional data only links to the ProdID.  I'm trying to instruction box allows to send the parent a second table (ProdID) code if the sku is there, or a third table if it is found on this table.  The main reason (in this case) I have to this ProdID is I can join the dimensional data of a fourth table.

My current query:

SELECT / * + USE_HASH (dbin, sku, xProdID, msr) * /.

dbin.snapshot_date, dbin.bin_id, dbin. ISBN,

CASE WHEN sku. ProdID IS NULL THEN xProdID.ITEM_AUTHORITY_ID

Of ANOTHER sku. ProdID

END ProdIDMaster,

dbin. OWNER, dbin. QUANTITY, dbin. CONTAINER_ID,

MSR. HEIGHT, msr. WIDTH, msr. LENGTH, msr. WEIGHT, msr. DIMENSIONAL_UOM, msr. WEIGHT_UOM,

MSR. HEIGHT * msr. WIDTH * msr. LENGTH as a Volume

OF D_BIN_ITEMS dbin

SKU of LEFT JOIN O_FCSKUS ON dbin. ISBN = sku. FCSKU

LEFT JOIN (SELECT * FROM D_FNSKU_ProdID_MAP)

WHERE REGION_ID = 1

AND SNAPSHOT_DAY = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')) xProdID

ON dbin. ISBN = xProdID.FULFILLMENT_NETWORK_SKU

LEFT JOIN (SELECT * FROM D_MP_ProdID_PKG_MEASUREMENTS)

WHERE REGION_ID = 1 AND MARKETPLACE_ID = 1 AND PACKAGE_TYPE_ID = 1) msr

ON ProdIDMaster = msr. ProdID

WHERE dbin. WAREHOUSE_ID = "PHL5."

AND dbin. Snapshot_date = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')

AND dbin.bin_id like '% P-1-R '.

ORDER BY dbin.bin_id;

The error I receive:

Statement 1 is invalid. ORA-00904: "ProdIDMaster": invalid identifier

ProdIDMaster appears only in two places, an alias for the case statement, as well as a side of the join statement.  If I simply change the alias name, it has no effect, so I can only assume the question is how I refer to results of the case statement. I also tried to reach the word 'CASE', which returned "1 statement is not valid. "ORA-00904:"The MATTER": invalid identifier.

Any help or advice would be greatly appreciated.

Post edited by: 8ea4344e-80ea-44e7-b8ac-d482be7245a7 I made a mistake when I posted the code.  The ProdID_ID shown in the join should have been ProdIDMaster.  I need to change this due to the fact that the name of the column used (which is what I based my alias on) may have been considered confidential information. All the other columns names remained unchanged.

Hello

8ea4344e-80EA-44e7-B8AC-d482be7245a7 wrote:

Hello everyone;

I can't with a query where I use a case statement to create a new column and attempt to reach an additional table on the resulting column.  I am fairly new to this and learn by trial and error, so if you think that it looks a little ugly or ineffective, I won't be offended.  It is used on my interface based on the web of companies, while I am not able to answer some basic questions such as the version of db.

My need to use the case statement is the result of some strange methods and somewhat contradictory in order to link the product subcodes (sku, fcsku, fnsku), to a product code parent (ProdID).  In this case, the inventory is stored in the first table with one of the few types of premises SKUs, however the dimensional data only links to the ProdID.  I'm trying to instruction box allows to send the parent a second table (ProdID) code if the sku is there, or a third table if it is found on this table.  The main reason (in this case) I have to this ProdID is I can join the dimensional data of a fourth table.

My current query:

SELECT / * + USE_HASH (dbin, sku, xProdID, msr) * /.

dbin.snapshot_date, dbin.bin_id, dbin. ISBN,

CASE WHEN sku. ProdID IS NULL THEN xProdID.ITEM_AUTHORITY_ID

Of ANOTHER sku. ProdID

END ProdIDMaster,

dbin. OWNER, dbin. QUANTITY, dbin. CONTAINER_ID,

MSR. HEIGHT, msr. WIDTH, msr. LENGTH, msr. WEIGHT, msr. DIMENSIONAL_UOM, msr. WEIGHT_UOM,

MSR. HEIGHT * msr. WIDTH * msr. LENGTH as a Volume

OF D_BIN_ITEMS dbin

SKU of LEFT JOIN O_FCSKUS ON dbin. ISBN = sku. FCSKU

LEFT JOIN (SELECT * FROM D_FNSKU_ProdID_MAP)

WHERE REGION_ID = 1

AND SNAPSHOT_DAY = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')) xProdID

ON dbin. ISBN = xProdID.FULFILLMENT_NETWORK_SKU

LEFT JOIN (SELECT * FROM D_MP_ProdID_PKG_MEASUREMENTS)

WHERE REGION_ID = 1 AND MARKETPLACE_ID = 1 AND PACKAGE_TYPE_ID = 1) msr

ON ProdIDid_ID = msr. ProdID

WHERE dbin. WAREHOUSE_ID = "PHL5."

AND dbin. Snapshot_date = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')

AND dbin.bin_id like '% P-1-R '.

ORDER BY dbin.bin_id;

The error I receive:

Statement 1 is invalid. ORA-00904: "ProdIDMaster": invalid identifier

ProdIDMaster appears only in two places, an alias for the case statement, as well as a side of the join statement.  If I simply change the alias name, it has no effect, so I can only assume the question is how I refer to results of the case statement. I also tried to reach the word 'CASE', which returned "1 statement is not valid. "ORA-00904:"The MATTER": invalid identifier.

Any help or advice would be greatly appreciated.

Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

Always say what version of Oracle you are using (for example, 11.2.0.2.0).  Use "SELECT * VERSION of $ v;" to get it.

See the FAQ forum: Re: 2. How can I ask a question on the forums?

When you define an alias for column (such as PriodIDMaster) in the SELECT a query clause, you can use the alias in the ORDER byclause in this request, but this is the only place in this same query, where you can use it.  If you want to use anywhere, like in a join condition, then calculate the new column in a subquery; then you can use it anywhere you want in a Super request.

I see expression BOX (not the same as a declarationBOX) where when ProdIDMaster is defined, but I do not see where it is used.  Are you sure that you posted the code that is causing the problem?

Tags: Database

Similar Questions

  • In SQL Developer, is it possible to send the results of a sql statement?

    In SQL Developer, is it possible to send the results of a sql statement?

    Right-click on the query results pane, select "Export data" in the context menu, then select "xls".

  • How to loop through the results of a select statement in a process flow?

    Hello

    I use Warehouse Builder 10 g R2.

    I'm trying to implement a loop in a process stream that runs through the results of a select statement.

    In pl/sql, it would be implemented as a for loop by using a slider, but I simply doesn't work how to do this using the loops in the process flow.

    Someone at - it ideas?

    Thank you
    Liffey

    Liffey,
    Look at this thread
    For or while loop a loop in the process flow

    Kind regards
    Oleg

  • Problem in the counting by SQL case statement

    I have a table with 3 columns-

    create table execution_stg)
    number of alc_td_id
    number of exe_td_id
    src_sys varchar2 (50)
    )

    I want to get the number of records with alc_td_id not null and not null exe_td_id and total count by src_sys.

    When to use a query like this-

    SELECT src_sys,
    CASE
    WHEN alc_td_id IS NOT NULL
    THEN THE SUM (1)
    END as alc_ac_cnt,
    CASE
    WHEN exe_td_id IS NOT NULL
    THEN THE SUM (1)
    END AS td_ac_cnt, COUNT (*) AS total_cnt
    Of execution_stg
    GROUP BY src_sys


    I get ORA-00979 - isn't a group by expression.

    What should I do?

    Thank you
    -Christian Plantier S

    Edited by: girija_pathak may 3, 2010 12:55

    Edited by: girija_pathak may 3, 2010 13:05

    Never mind...

    Edited by: AlanWms may 3, 2010 16:09

  • Function that returns the results of a select statement

    Hello

    I would like to create a feature on the famous HR Departments oracle table to select * from him. I don't know how to do it.

    Is someone can help me?.

    Thank you

    Oracle stored functions cannot return result sets directly but can return the REF CURSOR. Please read [optimize result set retrieval using ODP.NET and Ref Cursor | http://www.oracle.com/technology/pub/articles/mastering_dotnet_oracle/williams_refcursors.html] which gives complete examples in PL/SQL for the side Server and VB. NET client side.

  • How to use the Substring function with Case statement.

    Hi all

    I have a requirement where I have to use the substring function on the ground for the report criteria.
    FOR EXAMPLE
    I branch domain name where I have all the information of the branch names, now some of the branch names are too large with an extension after the name.
    now I want substing it, but the length of characters varies for each branch.
    so is it possible where we use a box where we can define if the character of name plug exceed a value then he substing with this length.

    Try something like this:

    LENGTH WHEN CARTER (tablename. Branch_Name) > n THEN SUBSTRING (...) Of ANOTHER tablename. Branch_Name END

    where n is the number of characters that you want to start the break.

  • Case statement "when IN the cursor.

    Hi people.

    I wonder if it is possible to use the IN within a CASE statement?

    I'm trying to see if a parameter is certain dates in another table. I have a cursor declared which points to this date column, and looks like my case statement so

    case parameter_date IN certain_dates then if_holiday: = 1 else if_holiday: = 2 end;

    It doesn't when I try to compile. And my procedure is listed as invalid.

    Thanks for any help :)

    I have the Case statement without the right to choose?

    Only if specify you on literals as follows

    in ('WHATEVER', 'DUDE', 'RUG')
    

    You cannot use a variable.

    I guess it may be easier if I just use an if statement.

    Ah, is this a CASE of PL/SQL rather than a SQL CASE? Not that it makes a lot of difference. In any case, if this world is IF... ELSIF easier than the CASE? I mean, I'm a traditionalist, and I prefer even the syntax of the CASE.

    Cheers, APC

    blog: http://radiofreetooting.blogspot.com

  • How to remove the additional summary of the result of the query

    All,

    I create a derived table two tables and then join the result then using function group but the result is to summarize a number of additional time, can correct all my request. Here are the tables and relevant data.

    CREATE TABLE SHP_DW_TEMP_DEL_WEIGHT_TB

    (

    CUSTOMER_ID NUMBER DEFAULT NULL,

    NUMBER OF CARRIER_ID,

    DATE OF BILL_DATE,

    VARCHAR2 (200 BYTE) SERVICE,

    NUMBER OF WEIGHT,

    Create_date DATE default sysdate,

    SHIPPER_ID NUMBER DEFAULT NULL

    )

    CREATE TABLE SHP_DW_TEMP_DEL_SPEND_TB

    (

    CUSTOMER_ID NUMBER DEFAULT null,

    NUMBER OF CARRIER_ID,

    DATE OF BILL_DATE,

    VARCHAR2 (200 BYTE) SERVICE,

    NUMBER OF COST,

    Create_date DATE default sysdate,

    SHIPPER_ID NUMBER DEFAULT of null

    )

    CREATE TABLE SHP_DW_INTERM_TB

    (

    JAVA_SESSION_ID VARCHAR2 (1000 BYTE),

    USER_ID NUMBER,

    CUSTOMER_ID NUMBER DEFAULT NULL,

    CLIENT_NAME VARCHAR2 (100 BYTE),

    NUMBER OF CARRIER_ID,

    CARRIER_NAME VARCHAR2 (100 BYTE),

    NUMBER OF IS_LTL_CARRIER

    SHIPPER_GROUP_ID NUMBER DEFAULT NULL,

    SHIPPER_ID NUMBER DEFAULT NULL,

    SHIPPER_NAME VARCHAR2 (100 BYTE),

    CREATE_DATE DATE DEFAULT SYSDATE,

    FREIGHT_RANK NUMBER DEFAULT of null

    )

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 602, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 243, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), ' FIRST INTERNATIONAL AIRPORT THE NIGHT ', 1.8, TO_DATE (MARCH 25, 2014 04:28:29 ',' ' DD/MM/YYYY HH24:MI:SS));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 8203.5, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 2351.1, (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 2979.7, (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 8622.1, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 10358.4, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', 2899, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 2597.1, (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 121, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 9015.5, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)

    Values

    (664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 729, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))

    COMMIT;

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 356.65, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 181.19, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), ' FIRST INTERNATIONAL AIRPORT THE NIGHT ', 134.45, TO_DATE (MARCH 21, 2014 03:13:16 ',' ' DD/MM/YYYY HH24:MI:SS));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 7267.92, (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 27755.2, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 8192.35, (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 26388.53, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 8825.98, (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 31653.45, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 7901.07, (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 167.73, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 959.85, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB

    (CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)

    Values

    (664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 28209.22, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))

    COMMIT;

    Insert into msidw.shp_dw_interm_tb

    (java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)

    Values

    ("E52AFB0183301775CD882C214A34F54F", 18686, 664, NULL, 22,)

    "FedEx", 0, NULL, NULL, NULL,

    TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);

    Insert into msidw.shp_dw_interm_tb

    (java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)

    Values

    ("E52AFB0183301775CD882C214A34F54F", 18686, 664, NULL, 23,)

    'DHL', 0, NULL, NULL, NULL,

    TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);

    Insert into msidw.shp_dw_interm_tb

    (java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)

    Values

    ("CA5AC1C5630D70B2E80E8E2A427DA249", 18686, 664, NULL, 21,)

    'UPS', 0, NULL, NULL, NULL,

    TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);

    Insert into msidw.shp_dw_interm_tb

    (java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)

    Values

    ("CA5AC1C5630D70B2E80E8E2A427DA249", 18686, 664, NULL, 22,)

    "FedEx", 0, NULL, NULL, NULL,

    TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);

    Insert into msidw.shp_dw_interm_tb

    (java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)

    Values

    ("CA5AC1C5630D70B2E80E8E2A427DA249", 18686, 664, NULL, 23,)

    'DHL', 0, NULL, NULL, NULL,

    TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);

    Insert into msidw.shp_dw_interm_tb

    (java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)

    Values

    ("E52AFB0183301775CD882C214A34F54F", 18686, 664, NULL, 21,)

    'UPS', 0, NULL, NULL, NULL,

    TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);

    COMMIT;

    This is the query:

    SELECT

    DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M,

    DER_COST_PER_POUND_INTL_MONTH. SERVICE,

    DER_COST_PER_POUND_INTL_MONTH. WEIGHT,

    DER_SPEND_BY_SERV_INTL_MONTHLY. COST

    Of

    (

    SELECT CUSTOMER_ID, CARRIER_ID, to_char (SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE, 'MM - YY') as BILL_DATE_M,

    (CASE

    WHEN (LIKE '% GROUND INTERNATIONAL %' service

    OR service LIKE '% INTERNATIONAL HOME DELIVERY %'

    OR a service LIKE ' % international airport FEDEX GROUND-PRP %'

    OR a service LIKE ' % international airport FEDEX GROUND-RTLABEL %'

    OR a service LIKE '% international airport FEDEX GROUND %'

    OR service LIKE ' % STANDARD.

    OR service LIKE ' % worldwide %.

    )

    AND (NOT LIKE '% FEDEX INTL ECONOMY FRT %' service

    AND service NOT LIKE ' % of the ECONOMY of FEDEX INTL.

    "AND NOT AS service ' % airport % OF CARGO OF the ECONOMY".

    "AND NOT AS service ' % airport % OF the ECONOMY.

    AND NOT LIKE '% ECONOMY MAILSERVICE % INTL' service

    AND NOT LIKE «% % ECONOMY» service

    AND NOT LIKE '% FEDEX EXPRESS SAVER % INTL' service

    AND NOT LIKE '% WW SAVER %' service

    AND NOT LIKE '% CANADIAN % SAVER' service

    AND NOT LIKE '% UPS SAVER %' service

    AND NOT LIKE '% FEDEX INTL PRIORITY FRT %' service

    AND NOT LIKE '% FEDEX INTL PRIORITY %' service

    AND NOT LIKE '% MAILSERVICE INTL PRIORITY %' service

    AND service NOT AS '% PRIORITY % PROPOSED international airport'

    AND service NOT AS

    'INTERNATIONAL PRIORITY DIRECTDISTRIBUTION % AIRPORT %'

    AND service NOT LIKE '% ACCELERATED %.

    AND service NOT AS ' % international airport 1 DAY FREIGHT %'

    AND service NOT AS ' international airport FIRST NIGHT % %'

    AND NOT AS '% FEDEX INTERNATIONAL FIRST' service

    AND service NOT AS '% international airport MAILSERVICE-BONUS %'

    AND service NOT AS '% UNKNOWN CODE % BASIC SERVICES international airport'

    )

    THEN "ground".

    END

    ) service.

    weight,

    shipper_id

    OF SHP_DW_TEMP_DEL_WEIGHT_TB

    where

    SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE > = trunc (add_months ((CASE WHEN sysdate < next_day (trunc (sysdate, 'MY')-1, 'MONDAY'), trunc(sysdate,'MON')-1 ELSE END sysdate), - 12), "MM") and SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE < trunc (last_day (add_months ((CASE WHEN sysdate < next_day (trunc (sysdate, 'MY')-1, 'MONDAY'), trunc(sysdate,'MON')-1 ELSE END sysdate), - 1)))

    and extract (bill_date months) = 02

    and customer_id = 664

    GROUP BY

    CARRIER_ID, CUSTOMER_ID, to_char (SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE, "MM - YY"), service, weight, SHIPPER_ID

    ) DER_COST_PER_POUND_INTL_MONTH,.

    (

    SELECT CUSTOMER_ID, CARRIER_ID, to_char (SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE, 'MM - YY') as BILL_DATE_M,

    (CASE

    WHEN (LIKE '% GROUND INTERNATIONAL %' service

    OR service LIKE '% INTERNATIONAL HOME DELIVERY %'

    OR a service LIKE ' % international airport FEDEX GROUND-PRP %'

    OR a service LIKE ' % international airport FEDEX GROUND-RTLABEL %'

    OR a service LIKE '% international airport FEDEX GROUND %'

    OR service LIKE ' % STANDARD.

    OR service LIKE ' % worldwide %.

    )

    AND (NOT LIKE '% FEDEX INTL ECONOMY FRT %' service

    AND service NOT LIKE ' % of the ECONOMY of FEDEX INTL.

    "AND NOT AS service ' % airport % OF CARGO OF the ECONOMY".

    "AND NOT AS service ' % airport % OF the ECONOMY.

    AND NOT LIKE '% ECONOMY MAILSERVICE % INTL' service

    AND NOT LIKE «% % ECONOMY» service

    AND NOT LIKE '% FEDEX EXPRESS SAVER % INTL' service

    AND NOT LIKE '% WW SAVER %' service

    AND NOT LIKE '% CANADIAN % SAVER' service

    AND NOT LIKE '% UPS SAVER %' service

    AND NOT LIKE '% FEDEX INTL PRIORITY FRT %' service

    AND NOT LIKE '% FEDEX INTL PRIORITY %' service

    AND NOT LIKE '% MAILSERVICE INTL PRIORITY %' service

    AND service NOT AS '% PRIORITY % PROPOSED international airport'

    AND service NOT AS

    'INTERNATIONAL PRIORITY DIRECTDISTRIBUTION % AIRPORT %'

    AND service NOT LIKE '% ACCELERATED %.

    AND service NOT AS ' % international airport 1 DAY FREIGHT %'

    AND service NOT AS ' international airport FIRST NIGHT % %'

    AND NOT AS '% FEDEX INTERNATIONAL FIRST' service

    AND service NOT AS '% international airport MAILSERVICE-BONUS %'

    AND service NOT AS '% UNKNOWN CODE % BASIC SERVICES international airport'

    )

    THEN "ground".

    END

    ) service.

    COST,

    SHIPPER_ID

    OF SHP_DW_TEMP_DEL_SPEND_TB

    where

    SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE > = trunc (add_months ((CASE WHEN sysdate < next_day (trunc (sysdate, 'MY')-1, 'MONDAY'), trunc(sysdate,'MON')-1 ELSE END sysdate), - 12), "MM") and SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE < trunc (last_day (add_months ((CASE WHEN sysdate < next_day (trunc (sysdate, 'MY')-1, 'MONDAY'), trunc(sysdate,'MON')-1 ELSE END sysdate), - 1)))

    and extract (bill_date months) = 02

    and customer_id = 664

    GROUP OF CUSTOMER_ID, CARRIER_ID, to_char (SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE, "MM - YY"), service, COST, SHIPPER_ID

    ) DER_SPEND_BY_SERV_INTL_MONTHLY,.

    SHP_DW_INTERM_TB

    WHERE

    (NVL (DER_SPEND_BY_SERV_INTL_MONTHLY. CUSTOMER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. CUSTOMER_ID,-1))

    AND (DER_SPEND_BY_SERV_INTL_MONTHLY. CARRIER_ID = DER_COST_PER_POUND_INTL_MONTH. CARRIER_ID)

    AND (DER_SPEND_BY_SERV_INTL_MONTHLY. BILL_DATE_M = DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M)

    AND (DER_SPEND_BY_SERV_INTL_MONTHLY. SERVICE = DER_COST_PER_POUND_INTL_MONTH. (SERVICE) - MNKB

    AND (NVL (DER_SPEND_BY_SERV_INTL_MONTHLY. SHIPPER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. SHIPPER_ID,-1))

    AND (NVL (SHP_DW_INTERM_TB. CUSTOMER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. CUSTOMER_ID,-1))

    AND (SHP_DW_INTERM_TB. CARRIER_ID = DER_COST_PER_POUND_INTL_MONTH. CARRIER_ID)

    AND (NVL (SHP_DW_INTERM_TB. SHIPPER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. SHIPPER_ID,-1))

    AND

    (

    SHP_DW_INTERM_TB. JAVA_SESSION_ID in ('CA5AC1C5630D70B2E80E8E2A427DA249')

    AND

    SHP_DW_INTERM_TB. User_id in (18686)

    AND

    SHP_DW_INTERM_TB.IS_LTL_CARRIER (0)

    )

    GROUP BY

    DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M,

    DER_COST_PER_POUND_INTL_MONTH. WEIGHT,

    DER_SPEND_BY_SERV_INTL_MONTHLY. COST,

    DER_COST_PER_POUND_INTL_MONTH. SERVICE

    order of DER_COST_PER_POUND_INTL_MONTH.service

    The result I want is

    Billing date

    Service Weight Cost
    04/02/14
    On the ground
    121
    167.73
    11/02/14
    On the ground
    243
    181.19
    18/02/2014
    On the ground
    729
    959.85
    25/02/2014
    On the ground
    602
    356.65

    The above query gives each weight mapped to each cost, so the resulting values are summarizing to greater value than the above expected values.

    Can someone help me please how do I change my request to get my desired result.

    Kind regards

    Mr Kishore N. badin.

    SELECT DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M,

    DER_COST_PER_POUND_INTL_MONTH. SERVICE,

    DER_COST_PER_POUND_INTL_MONTH. WEIGHT,

    DER_SPEND_BY_SERV_INTL_MONTHLY. COST

    IN (SELECT CUSTOMER_ID,

    CARRIER_ID,

    TO_CHAR (SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE, 'DD-MM-YY') as BILL_DATE_M,

    BOX WHEN (LIKE '% GROUND INTERNATIONAL %' service

    OR service LIKE '% INTERNATIONAL HOME DELIVERY %'

    OR a service LIKE ' % international airport FEDEX GROUND-PRP %'

    OR a service LIKE ' % international airport FEDEX GROUND-RTLABEL %'

    OR a service LIKE '% international airport FEDEX GROUND %'

    OR service LIKE ' % STANDARD.

    OR service LIKE ' % worldwide %.

    )

    AND (NOT LIKE '% FEDEX INTL ECONOMY FRT %' service

    AND service NOT LIKE ' % of the ECONOMY of FEDEX INTL.

    "AND NOT AS service ' % airport % OF CARGO OF the ECONOMY".

    "AND NOT AS service ' % airport % OF the ECONOMY.

    AND NOT LIKE '% ECONOMY MAILSERVICE % INTL' service

    AND NOT LIKE «% % ECONOMY» service

    AND NOT LIKE '% FEDEX EXPRESS SAVER % INTL' service

    AND NOT LIKE '% WW SAVER %' service

    AND NOT LIKE '% CANADIAN % SAVER' service

    AND NOT LIKE '% UPS SAVER %' service

    AND NOT LIKE '% FEDEX INTL PRIORITY FRT %' service

    AND NOT LIKE '% FEDEX INTL PRIORITY %' service

    AND NOT LIKE '% MAILSERVICE INTL PRIORITY %' service

    AND service NOT AS '% PRIORITY % PROPOSED international airport'

    AND service NOT AS '% airport international PRIORITY DIRECTDISTRIBUTION %'

    AND service NOT LIKE '% ACCELERATED %.

    AND service NOT AS ' % international airport 1 DAY FREIGHT %'

    AND service NOT AS ' international airport FIRST NIGHT % %'

    AND NOT AS '% FEDEX INTERNATIONAL FIRST' service

    AND service NOT AS '% international airport MAILSERVICE-BONUS %'

    AND service NOT AS '% UNKNOWN CODE % BASIC SERVICES international airport'

    )

    THEN "ground".

    END of service,

    weight,

    shipper_id

    OF SHP_DW_TEMP_DEL_WEIGHT_TB

    where SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE > =.

    trunc (add_months (BOX WHEN sysdate< next_day(trunc(sysdate,'mon')="" -="">

    'MONDAY '.

    )

    THEN trunc (sysdate, 'MY') - 1

    Of ANOTHER sysdate

    END,

    -12

    ),

    "MM".

    )

    and SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE

    trunc (last_day (add_months (BOX WHEN sysdate< next_day(trunc(sysdate,'mon')="" -="">

    'MONDAY '.

    )

    THEN trunc (sysdate, 'MY') - 1

    Of ANOTHER sysdate

    END,

    -1

    )

    )

    )

    and extract (bill_date months) = 02

    and customer_id = 664

    GROUP CARRIER_ID,

    CUSTOMER_ID,

    TO_CHAR (SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE, 'DD-MM-YY'),

    service, weight, SHIPPER_ID

    ) DER_COST_PER_POUND_INTL_MONTH,.

    (SELECT CUSTOMER_ID,

    CARRIER_ID,

    TO_CHAR (SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE, 'DD-MM-YY') as BILL_DATE_M,

    BOX WHEN (LIKE '% GROUND INTERNATIONAL %' service

    OR service LIKE '% INTERNATIONAL HOME DELIVERY %'

    OR a service LIKE ' % international airport FEDEX GROUND-PRP %'

    OR a service LIKE ' % international airport FEDEX GROUND-RTLABEL %'

    OR a service LIKE '% international airport FEDEX GROUND %'

    OR service LIKE ' % STANDARD.

    OR service LIKE ' % worldwide %.

    )

    AND (NOT LIKE '% FEDEX INTL ECONOMY FRT %' service

    AND service NOT LIKE ' % of the ECONOMY of FEDEX INTL.

    "AND NOT AS service ' % airport % OF CARGO OF the ECONOMY".

    "AND NOT AS service ' % airport % OF the ECONOMY.

    AND NOT LIKE '% ECONOMY MAILSERVICE % INTL' service

    AND NOT LIKE «% % ECONOMY» service

    AND NOT LIKE '% FEDEX EXPRESS SAVER % INTL' service

    AND NOT LIKE '% WW SAVER %' service

    AND NOT LIKE '% CANADIAN % SAVER' service

    AND NOT LIKE '% UPS SAVER %' service

    AND NOT LIKE '% FEDEX INTL PRIORITY FRT %' service

    AND NOT LIKE '% FEDEX INTL PRIORITY %' service

    AND NOT LIKE '% MAILSERVICE INTL PRIORITY %' service

    AND service NOT AS '% PRIORITY % PROPOSED international airport'

    AND service NOT AS '% airport international PRIORITY DIRECTDISTRIBUTION %'

    AND service NOT LIKE '% ACCELERATED %.

    AND service NOT AS ' % international airport 1 DAY FREIGHT %'

    AND service NOT AS ' international airport FIRST NIGHT % %'

    AND NOT AS '% FEDEX INTERNATIONAL FIRST' service

    AND service NOT AS '% international airport MAILSERVICE-BONUS %'

    AND service NOT AS '% UNKNOWN CODE % BASIC SERVICES international airport'

    )

    THEN "ground".

    END of service,

    COST,

    SHIPPER_ID

    OF SHP_DW_TEMP_DEL_SPEND_TB

    where SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE > =.

    trunc (add_months (BOX WHEN sysdate< next_day(trunc(sysdate,'mon')="" -="">

    'MONDAY '.

    )

    THEN trunc (sysdate, 'MY') - 1

    Of ANOTHER sysdate

    END,

    -12

    ),

    "MM".

    )

    and SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE

    trunc (last_day (add_months (BOX WHEN sysdate< next_day(trunc(sysdate,'mon')="" -="">

    'MONDAY '.

    )

    THEN trunc(sysdate,'MON')-1

    Of ANOTHER sysdate

    END,

    -1

    )

    )

    )

    and extract (bill_date months) = 02

    and customer_id = 664

    CUSTOMER_ID GROUP,

    CARRIER_ID,

    TO_CHAR (SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE, 'DD-MM-YY'),

    service, COST, of SHIPPER_ID

    ) DER_SPEND_BY_SERV_INTL_MONTHLY,.

    SHP_DW_INTERM_TB

    WHERE (NVL (DER_SPEND_BY_SERV_INTL_MONTHLY. CUSTOMER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. CUSTOMER_ID,-1))

    AND (DER_SPEND_BY_SERV_INTL_MONTHLY. CARRIER_ID = DER_COST_PER_POUND_INTL_MONTH. CARRIER_ID)

    AND (DER_SPEND_BY_SERV_INTL_MONTHLY. BILL_DATE_M = DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M)

    AND (DER_SPEND_BY_SERV_INTL_MONTHLY. SERVICE = DER_COST_PER_POUND_INTL_MONTH. (SERVICE) - MNKB

    AND (NVL (DER_SPEND_BY_SERV_INTL_MONTHLY. SHIPPER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. SHIPPER_ID,-1))

    AND (NVL (SHP_DW_INTERM_TB. CUSTOMER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. CUSTOMER_ID,-1))

    AND (SHP_DW_INTERM_TB. CARRIER_ID = DER_COST_PER_POUND_INTL_MONTH. CARRIER_ID)

    AND (NVL (SHP_DW_INTERM_TB. SHIPPER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. SHIPPER_ID,-1))

    AND (SHP_DW_INTERM_TB. JAVA_SESSION_ID in ('CA5AC1C5630D70B2E80E8E2A427DA249')

    AND SHP_DW_INTERM_TB. User_id in (18686)

    AND SHP_DW_INTERM_TB.IS_LTL_CARRIER (0)

    )

    GROUP OF DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M,

    DER_COST_PER_POUND_INTL_MONTH. WEIGHT,

    DER_SPEND_BY_SERV_INTL_MONTHLY. COST,

    DER_COST_PER_POUND_INTL_MONTH. SERVICE

    order DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M, DER_COST_PER_POUND_INTL_MONTH.service

    BILL_DATE_M SERVICE WEIGHT COST
    02/04/14 On the ground 121 167.73
    02/11/14 On the ground 243 181.19
    18/02/14 On the ground 729 959.85
    25/02/14 On the ground 602 356.65

    Concerning

    Etbin

  • Problem with CASE statements

    Hi all

    I have a calculation in a report of Discoverer Desktop with 29 instructions BOX and still 2 case statements more to add. The problem is that my report freezes and fails to run due to the excessive number of case statements. I need to put the 31 statemnts cases in the report, how do I do this? Is there another way to do it without causing the report to freeze?

    Below is part of my instructions box just to show you what I'm doing:

    CASE WHEN Ex = 'MM' AND THEN of OTHER NULL result (', ')
    CASES WHERE Ex = "PP" AND result IN (40,35,30,25) THEN NULL OTHERWISE
    CASE WHEN Ex = he's ' AND result IN (' a ',' B', 'C', d ') THEN NULL OTHERWISE
    -CASE WHEN Ex = 'IO' AND THEN of OTHER NULL result ('Distinction', 'Merit')
    -CASE WHEN Ex IN ('ZZ', 'WW', 'SS', 'KK') AND ('PASS', 'P') THEN to ANOTHER NULL result...

    The last statement should be BOX WHEN... THEN NULL OTHERWISE 1 END END END END...

    Help, please. Thank you.

    Hello
    You have reached the limit of characters in a calculation.

    Try to set into a single statement as follows:

    CASE WHEN Ex = 'MM' AND THEN of OTHER NULL result (', ')
    WHEN Ex = "PP" AND as a result (40,35,30,25) THEN NULL OTHERWISE
    WHEN Ex = he's ' AND result IN (' a ',' B', 'C', d ') THEN NULL OTHERWISE
    WHEN Ex = 'IO' AND THEN of OTHER NULL result ('Distinction', 'Merit')
    WHEN Ex IN ('ZZ', 'WW', 'SS', 'KK') AND ('PASS', 'P') THEN to ANOTHER NULL result...

    The last statement should be BOX WHEN... THEN NULL OTHERWISE 1 END

    Another option is to combine all the statements of NULL in a series of gold options like this:

    BOX WHEN
    (Ex = 'MM' AND the result in (', am')) OR
    (Ex = "PP" AND result IN (40,35,30,25)) OR
    (Ex = he's ' AND translated BY (' a ',' B', 'C', ')) OR
    (Ex = 'IO' AND as a result ('Distinction', "according to merit")) OR
    (Ex IN ("ZZ", "WW", "SS", "KK") AND result IN ('PASS', 'P')) THEN ANOTHER NULL...

    Best wishes
    Michael

  • The Variable value based on the results of SQL query

    With the help of OBIEE 11.1

    Is it possible to set the value of a variable presentation of the results of a SQL statement?

    Scenario:

    I have 2 topics.

    SubjectArea1

    Text1

    Date1

    SubjectArea2

    Field1

    Field2

    UpdateDate

    I have an analysis that uses only the SubjectArea2.

    Using a dashboard quickly, the user must be able to select Text1 in the other topic area (SubjectArea1).

    Assuming that selection will be stored in a variable of presentation (SelectedText),

    The filter in the analysis should be something like

    Upper UpdateDate to @{SelectedDate}

    How can I set a variable (SelectedDate) using a SQL statement?

    Something like this:

    SELECT "Date1" TO "SubjectArea1" WHERE "Text1" = @{SelectedText}

    So the command prompt text selection should give a date that is used to filter the second review?

    If so:

    The prompt on SA1.textCol

    hidden analysis who is invited on SA1.texCol has SA1.dateCol in the criteria

    Analysis SA2.dateCol is filetered on basis of the results of another analysis (any value analysis hidden SA1.dateCol)

  • Need to print the results of a query in a CASE statement

    I want to print the results of a query in a CASE statement:

    SELECT RUN_STATUS

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0 THEN 'NO JOBS RAN AFTER' |) (select sysdate - XXAFL_MINUTES MINUTE)

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where START_TS >

    (sélectionnez sysdate-MINUTES de XXAFL_MINUTES)) where RUN_STATUS is not null; e

    The query above subtracted 5 minutes from SYSDATE and he shoots XXAFL_MINUTES. I am doing this because we could change the number of minutes in the future. I want to print the number of minutes in the case statement.

    If I execute this statement, it throws an error stating:

    ORA-00937: not a single group group function

    00937 00000 - 'not a single-group function.

    * Cause:

    * Action:

    Error on line: 1 column: 96

    How can I include "select sysdate - MINUTES of XXAFL_MINUTES" in the CASE that it calculates the number of minutes and it prints with the results.

    Thanks in advance!

    Hey guys,.

    I found the solution:

    SELECT

    RUN_STATUS | TO_CHAR ((sélectionnez sysdate-MINUTES de XXAFL_MINUTES), 'HH24:MI:SS')

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0

    THEN "NO JOB RAN.

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where

    START_TS > (select sysdate - XXAFL_MINUTES MINUTE))

    where

    RUN_STATUS is not null;

    The output:

    NO JOBS RAN AFTER 09:07:54

    Thanks to you all!

  • Syntax of the case statement / WHEN

    The table I use a depreciation per fiscal year and the fiscal period.  I try to have the amount of depreciation to go to 2 different columns based on the fiscal year and the fiscal year.  I'm doing it with a nested case statement. I know that is not correct, because I get the message ORA-00905.  I'm relatively new to sql and it is contribtuing to my problem as well.  Here is the code I have and suggestions / corrections would be appreciated.  Thanks for the help...

    SELECT

    lao PDR. DEPTID as DEPTID,

    lao PDR. ASSET_ID as ASSET_NO,

    PA. Descr as DESCRIPTION,

    lao PDR. ACCOUNT_AD as AD_ACCT,

    PDL. DE_ACCT, to take into ACCOUNT

    lao PDR. ADEATH as AMT_DEPR,

    PDL. JOURNAL_ID as JRNL_ID,

    PDL. JOURNAL_DATE as JRNL_DT,

    lao PDR. FISCAL_YEAR as FY,

    lao PDR. ACCOUNTING_PERIOD AP,

    CASE

    WHEN RDP. FISCAL_YEAR = 2014 THEN

    WHEN RDP. PERIOD ACCOUNTANT = 11 THEN pdr. DEPR

    END AS CURR_MONTH,

    CASE

    WHEN RDP. FISCAL_YEAR <>2014

    WHEN RDP. ACCOUNTING PERIOD <>11 THEN pdr. DEPR

    END AS PRIOR_MONTH

    OF PS_DEPR_RPT pdr

    INNER JOIN PS_DIST_LN pdl

    THE pdl. BOOK = pdr. BOOK

    AND pdl. BUSINESS_UNIT = pdr. BUSINESS_UNIT

    AND pdl. FISCAL_YEAR = pdr. FISCAL_YEAR

    AND pdl. ACCOUNTING_PERIOD = pdr. ACCOUNTING_PERIOD

    AND pdl. ASSET_ID = pdr. ASSET_ID

    AND pdl. CF_SEQNO = pdr. CF_SEQNO

    INNER JOIN PS_ASSET PA

    WE pa. ASSET_ID = pdl. ASSET_ID

    AND pa. BUSINESS_UNIT = pdl. BUSINESS_UNIT

    WHERE

    lao PDR. BUSINESS_UNIT = "A0465.

    AND pdr. BOOK = 'RUN '.

    AND ((pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 11) OR (pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 10))

    Hello

    2713822 wrote:

    Thank you... I appreciate the information you provide when you answer these questions.  I always try to get the amount (from the same column) for 2 rows in different columns.  I tried the LAST_VALUE and LAG but it took a long time for the queries to run, I'm looking for another way to do the same.  I'm only using SQL to retrieve data.  I don't have the ability to create or insert.

    I looked the information above and the CASE statement to look like this:

    CASE

    WHEN RDP. FISCAL_YEAR = 2014

    AND pdr. ACCOUNTING_PERIOD = 11

    THEN the RDP. ADEATH AS CURR_MONTH

    ON THE OTHER

    lao PDR. ADEATH AS MONTHS PREVIOUS

    END

    But I'm now getting an "ORA-00905: lack of keyword" message.

    What I'm trying to do is to draw 2 lines 1 to 2014 / 11 and another for 2014 / 10.  The amount for the period 2014 / 11 should go in the current column and the amount for the period 2014 / 10 should go in the previous column.

    Before current assets management

    01 AB01 50.01 50.03

    ....

    If you want to give an alias for a column, then you can say "AS nome_alias" after that tell you what that is in this column.

    'AS nome_alias' applies to the entire column.  Cannot use 'alias_name' in the middle of an expression, for example, in the middle of a CASE expression, before the END keyword.

    If you want to have 2 separate output columns, curr_month and prior_month to your output, you must then 2 separate columns in your SELECT clause.  for example:

    SELECT pdr.branch

    pdr.asset

    CASE

    WHEN pdr.fiscal_year = 2014

    AND pdr.accounting_period = 11

    THEN pdr.depr

    END AS curr_month

    CASE

    WHEN...

    THEN...

    END AS prior_month

    PDR

    ;

    If post you some sample data (CREATE TABLE and INSERT statements), the results and explanations, I could show you how to complete the... sections.

    To find out what version of Oracle you have, use

    SELECT *.

    SINCE the release of v$.

    The output can be messy, like this:

    BANNER

    -------------------------------------------------------------------

    CON_ID

    ----------

    12 c Oracle database Release 12.1.0.1.0 - 64 bit Production

    0

    PL/SQL Release 12.1.0.1.0 - Production

    0

    CORE Production 12.1.0.1.0

    0

    AMT for 64-bit Windows: Version 12.1.0.1.0 - Production

    0

    NLSRTL Version 12.1.0.1.0 - Production

    0

    The important thing is the number 5 parts on the first line; 12.1.0.1.0 in the example above.

  • Dynamic transformations (Case statements) conducted through the user interface

    Hello

    I have a vision that a lot of business logic with values coded hard and would like to re - design the view make the transformation of dynamic business logic. I would like to give an example to tell the requirement in detail with the example below.

    Example SQL view: -.

    SELECT

    A.EMP_ID,

    A.EMP_NAME,

    BOX WHEN A.STATE = 'CA' AND A.DEPT_CODE = "C123" THEN 10 '

    WHEN ELSE A.STATE = 'NJ' AND A.DEPT_CODE IN ('N111', 'N454') AND A.GRADE = 'AAA' THEN '08'

    ELSE END '00' AS TAX_RATE,

    CASE WHEN A.JOIN_DT > = '20010101' OR (A.EMP_ID IN ('E134', "E456") OR A.DEP_CDE IN ('C222', "F222")) THEN '30'

    WHEN of OTHER A.JOIN_DT < '20010101' OR A.EMP_ID IN ('J133', "K556") THEN '20'

    ELSE '10' END AS BONUS_PERCENT

    A.ADDRESS

    FROM EMP A

    WHERE A.END_DATE > = '20000101'

    AND NVL (A.DEL_FL, 'N') = ' don't

    AND EXISTS (SELECT DEPT 1 D)

    WHERE D.EMP_ID = A.EMP_ID)

    Result: -.


    I wish I had the TAX_RATE and logic BONUS_PERCENT dynamically generated fields which has a lot of statements of case and hardcode, where the USER can change the logic and its values according to rank.

    To do this, we can design a table EMP_BUS to have fields that can be modified and the transformation of the UI logic. Please share your ideas in the design of the table or the applicable...

    Thank you in advance.

    Hello

    One way is to have all the settings defined by the user that is stored in a global Table Temporay and join at this table in your point of view.  The advantage of a global temporary Table is that each session has its own set of parameters which does not interfere with the other, so you can have multiple sessions using the view at the same time, and everyone will see the results based on its own parameters.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    If you ask on a DML statement, such as UPDATE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or the tables changed when it's all over.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Select with case statement and a formula of the IIR

    Hi, I was looking to get help regarding a statement writing box with a statement select statement all. I tried to reproduce a formula IIf access well that just wanted to check that the query I wrote is correct, any advice would be appreciated.

    [code]

    Select *.

    Of

    (

    Select name, month, duration, volume, time_spent, date1, date2,.

    -case when 'date' > = 'date1' then '1' other '0' end as departure,.

    -case when 'date' < = "date2" then '1' other '0' as end ending

    Of

    (

    Select *.

    of call_1 cd

    inner join call_2 ON cd.name = cl.queue cl

    )

    )

    ;

    [/ code]

    I want to know is where I have my ' select name, etc, I would change that to select * to make it easier instead of typing all the field_names outside, but I don't know how to do and also what follows is 2 IIF formulas from an access database for the start of the final case statements so I just wanted check I wrote it correctly.

    [code]

    departure: IIf ([date] > = [date1], 1, 0)

    [/ code]

    [code]

    ending: IIf ([date] < = [date2], 1, 0)

    [/ code]

    Any advice would be appreciated.

    Hello

    Whenever you have any questions, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.

    If the output depends on what anyone outside the application itself (for example, when it is run) and then include a few different examples and the results you want of each given the same sample data. For example, "if I run on November 19, 2013, while the results should be... because... but if I run between November 21 and November 27, then the results should be... because...". »
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

    318f20b8-a3d0-4FB4-bb0f-73785250b7d4 wrote:

    Hi, I was looking to get help regarding a statement writing box with a statement select statement all. I tried to reproduce a formula IIf access well that just wanted to check that the query I wrote is correct, any advice would be appreciated.

    [code]

    Select *.

    Of

    (

    Select name, month, duration, volume, time_spent, date1, date2,.

    -case when 'date' > = 'date1' then '1' other '0' end as departure,.

    -case when "date."<= 'date2'="" then="" '1'="" else="" '0'="" end="" as="">

    Of

    (

    Select *.

    of call_1 cd

    inner join call_2 ON cd.name = cl.queue cl

    )

    )

    ;

    [/ code]

    I want to know is where I have my ' select name, etc, I would change that to select * to make it easier instead of typing all the field_names outside, but I don't know how to do and also what follows is 2 IIF formulas from an access database for the start of the final case statements so I just wanted check I wrote it correctly.

    [code]

    departure: IIf([date]>=[date1],1,0)

    [/ code]

    [code]

    ending: IIf ([date]<>

    [/ code]

    Any advice would be appreciated.

    DATE is not a function of Oracle; in fact, it's a terrible name for a column or function, because it blends with the DATE data type.

    In Oracle, the function SYSDATE returns the date and time, according to the clock on the database server.  So, SYSDATE can return a value as November 19, 2013 06:33:15.   If you want to midnight the same day (i.e., November 19, 2013 00:00:00) and then use TRUNC (SYSDATE).

    String literals (for example the string which consists 5 characters d, a, t, e, and 1) go inside the single quotes. Numbers and the names of columns only.

    If you want to include all the columns, more some calculated values, in a SELECT clause, then you must use a name table or alias before the *.  (See select_2 below.  To do this, assign the alias j to display online.)

    Maybe you wanted to say something like:

    Select *-it's select_1

    de)

    Select j. *-it's select_2

    , case when SYSDATE > = date1 then 1 or 0 end as departure

    , case when SYSDATE<= date2="" then="" 1="" else="" 0="" end="" as="">

    de)

    Select *-it's select_3

    of call_1 cd

    inner join call_2 ON cd.name = cl.queue cl

    ) j

    )

    ;

    As mentioned in a previous answer, you should be careful about the use of "SELECT *" in production code.

    In select_3, it would be better if you explicitly listed the columns you need.  It can improve efficiency and maintenance.  In this request, queue and the name will be always the same, so you probably don't want to include both of them in the result set, in any case.

    In select_1 and select_2, it is acceptable to use "SELECT *", assuming that select_3 is fixed.

    Moreover, there is no point in using subqueries here.  You can get the same results simply in a single query, without any subqueries.

  • EXTRACT function can be used directly in the CASE statement WHEN

    I wrote the following SELECT statement. The function 'calc_time_diff' is a stored function that subtracts two timestamps and returns the result to the total number of seconds. My DBA does not 'calc_time_diff' as a stored function, then, I replaced the third line (in bold) in the SELECT statement with this:

    COUNTY ( BOX WHEN (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +)

    (extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.

    (excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.

    extract ((DEUXIÈME à PARTIR de v_end_ts-v_st_ts) < 3600 THEN 1 END) less_than_1_hrs_count

    But the CASE above does not work. It returns the same value as COUNT (*). If the total number of tickets is 32 output will be

    total_tickets less_than_1_hrs_count

    32                                 32

    If I call the "calc_time_diff" then I get the correct result. What I'm doing wrong here?

    **********************************************************************************************************************************************************************

    SELECT

    Count (*) total_tickets,

    COUNTY ( CASE WHEN END of calc_time_diff (t.created_date, h.closed_date) < 3600 THEN 1) less_than_1_hrs_count

    OF n01.cc_ticket_info t

    JOIN IN-HOUSE

    (SELECT ticket_id, MAX (created_date) closed_date

    OF n01.cc_ticket_status_history

    WHERE ticket_status = 'CLOSED' AND created_date > = 18 August 2013 ' AND created_date < (to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY)

    GROUP BY ticket_id

    ) h

    WE (t.ticket_id = h.ticket_id)

    INNER JOIN n01.cc_ticket_notes n

    WE (n.created_date = h.closed_date)

    WHERE (t. ticket_status = 'NOTIFICATION' t.ticket_status 'CLOSED' = GOLD) AND t.created_date > = 18 August 2013 ' AND t.last_changed < to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY);

    ***********************************************************************************************************************************************************

    create or replace

    FUNCTION calc_time_diff)

    p_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %,

    p_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %)

    RETURN NUMBER

    AS

    v_no_sec NUMBER;

    v_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %;

    v_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %;

    BEGIN

    v_st_ts: = p_st_ts;

    v_end_ts: = p_end_ts;

    SELECT (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +.

    (extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.

    (excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.

    excerpt ((SECOND from v_end_ts-v_st_ts)

    IN v_no_sec

    DOUBLE;

    Return v_no_sec;

    END calc_time_diff;

    Hello

    You don't need a function defined by the user or the EXTRACT to find the difference between two timestamps.

    SELECT COUNT (*) AS total_tickets

    , COUNTY ( BOX WHEN h.closed_date < t.created_date="" +="" interval="" '1'=""> )

                         THEN 1

    END

    ) AS less_than_1_hrs_count

    ...

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

Maybe you are looking for

  • Cannot open disk images

    After you download several updated files (.dmg) - none will open more: for example; How can I solve this problem? BR -Larry

  • Configuration of gestures magic mouse 2

    I don't have the option to configure on my mouse gestures. I'm running OS X 10.9.5 on my MacBook Pro. I have to upgrade to another version to use this feature?

  • Hi I don't remember security questions

    Hi I don't remember security questions for apple ID. and when I want to sign onther mail is reserved and change my 300 DPI question answering security question. means, I need help I can't hold my securety question and I can't change it. Help, please

  • WiFi and Bluetooth drivers for laptop HP 15-r022TX

    Hello Which driver should I insall to make the Wifi and the Bluetooth works on laptop HP 15-r022TX? I recently bought the laptop HP 15-r022TX from flipkart I installed the ultimate Windows 7 64-bit operating system. Here is the link to download drive

  • Exe files opening

    I managed to get WinRar as default program to open .exe files. Of course, this does not work, and I could not change it back. I even tried to open WinRar, but I couldn't, like WinRar itself was an .exe file! So I uninstalled WinRar and restarted my c