Case logic OF statement?

The problem:

In our society, there are several physical tables of the same type of information and data. Instead of storing everything in a single table, they differentiated by the company.

If the commands that may exist in sales_130 for the United States, but sales_244 to the Germany. Structure wise, they are the same. I have the cursor that identifies the data I need to acquire, and which company resides. So I go by the logistics company to get the data in the correct tables. Unfortunately, I need to join many tables and there are between 50 and 100 fields on that I need to update/delete/insert. Having to build all the SQL for each case when its only the tables that change becomes very tedious and difficult to manage.

Is there a way I can put a case or something like that in the part OF the clause so I did not do the following:
IF LOGISTIC_COMPANY = 130 THEN

INSERT INTO TEMP_ABCDEF
 (LOG_COMP, A,B,C,D,E,F)
 SELECT
   244, X.A, X.B, X.C, Y.D, Y.E, Y.F
 FROM
   ABC130 X,
   DEF130 Y
WHERE 
   X.A = Y.D(+);
   
COMMIT;

ELSIF LOGISTIC_COMPANY = 244 THEN
 
 INSERT INTO TEMP_ABCDEF
 (LOG_COMP, A,B,C,D,E,F)
 SELECT
   244, X.A, X.B, X.C, Y.D, Y.E, Y.F
 FROM
   ABC244 X,
   DEF244 Y
WHERE 
   X.A = Y.D(+);
   
COMMIT;  
ELSIF ...
To something like:
 INSERT INTO TEMP_ABCDEF
 SELECT
   130,
   X.A,
   X.B,
   X.C,
   Y.D,
   Y.E,
   Y.F
 FROM
 (  
 IF LOGISTIC_COMP = 130 THEN
   ABC130 X,
   DEF130 Y
 ELSIF LOGISTIC_COMP = 244 THEN
   ABC244 X,
   DEF244 Y
 ELSIF LOGISTIC_COMP = 387 THEN
   ABC387 X,
   DEF387 Y  
 ELSEIF ......

 )
WHERE 
   X.A = Y.D(+);
I tried different vain things.

In the light of the foregoing, I will for concept, not the correct syntax to explain because I have no idea how to put into words. There must be a way to simplify the SQL code so that I don't manage the business logic - as in the paintings and without having to rewrite while the IF-THEN-ELSE statements.

That's what it would look like, assuming that the only thing that changes is that the logistic_company still appears at the end tables:

  EXECUTE IMMEDIATE 'INSERT INTO TEMP_ABCDEF (LOG_COMP, A,B,C,D,E,F) ' ||
                    'SELECT ' || LOGISTIC_COMPANY  || ', X.A, X.B, X.C, Y.D, Y.E, Y.F'
                    'FROM   ABC' || LOGISTIC_COMPANY || ' X, DEF' || LOGISTIC_COMPANY || ' Y ' ||
                    'WHERE  X.A = Y.D(+)';
  COMMIT;

Published by: Thomas Morgan on June 3, 2013 10:29

Tags: Database

Similar Questions

  • CASE with MIN statement?

    I am trying to write a case statement that says what STAT is select E MIN (TERM)
    If there are several TERMS that are both low just choose No. Want a line by ID.
    Is this possible using case?

    Thank you.
    CREATE TABLE DAN_GR2
    (ID    VARCHAR2(12),
    TERM    VARCHAR2(12),
    STAT VARCHAR2(12)) 
    
    INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('1','5','E')
    INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('1','2','D')
    INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('1','9','E')
    INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('1','5','E')
    INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('2','1','E')
    INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('2','10','E')
    INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('3,'10','D')
    ID      TERM     STAT
    1     5     E
    1     2     D
    1     9     E
    1     5     E
    2     1     E
    2     10     E
    3       10      D
    Here you are
    ID   MIN_TERM   
    1     5     
    2     1
    3     NULL
    Use: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi

    Edited by: Chloe_19 09/12/2012 18:07

    Hello

    So, you don't want to ignore the whole when line stat! = 'E' (that ignores the single row with id = "3"). Put the condition ' stat = 'E' in the sill of the WHERE clause ignores line, so this isn't what you want.
    You want to just ignore the expression column. Put the same condition in a CASE expression that contols only this column.

    Here's one way:

    SELECT       id
    ,       MIN ( CASE
                     WHEN  stat = 'E'
                  THEN     term
                 END
               )          AS min_e_term
    FROM      dan_gr2
    GROUP BY  id
    ORDER BY  id
    ;
    
  • Help! It drives me crazy. Report CASE (missing operator) statement syntax error

    Hello

    Can anyone help with this SQL statement please. It uses a CASE statement but again I get a syntax error (missing operator) error message. The SQL statement runs without the CASE statement, so everything else is fine - it's just when I put the CASE back statement in.

    Here is the SQL statement:-

    SELECT transactions.ourRef, transactions.transDate, CASE WHEN transactions.transTypeID = 2 THEN transactionDetails.goodsVatable *-1 ELSE transactionDetails.goodsVatable END, transactionDetails.goodsNonVat, transactionDetails.VAT, transactionDetails.grandTotal, clients.clientCode, transTypes.transTypeDesc
    Operations, customers, transactionDetails, transTypes
    WHERE transactions.transID = transactionDetails.transID
    AND transactions.clientID = clients.clientID
    AND transactions.transTypeID = transTypes.transTypeID

    TransID = 2 means that it is a credit not instead of a Bill, that's why I want the goods vatable returned as a negative number.

    Thanks in advance.

    Wez

    Quote:
    .. .the customer wish for me to use a MS Access db

    Too bad that you said that in a first time. I think you can consider using IIF() with access.

    Syntax: IIf (expr, truepart, falsepart)

    SELECT transactions.ourRef,
    transactions.transDate,
    IIf (transactions.transTypeID = 2, transactionDetails.goodsVatable *-1, transactionDetails.goodsVatable).
    transactionDetails.goodsNonVat,
    transactionDetails.VAT,
    transactionDetails.grandTotal,
    clients.clientCode,
    transTypes.transTypeDesc
    Operations, customers, transactionDetails, transTypes
    WHERE transactions.transID = transactionDetails.transID
    AND transactions.clientID = clients.clientID
    AND transactions.transTypeID = transTypes.transTypeID

    Phil

  • Disqualification - CASE or DECODE statement writing

    Test

    Edited by: user4362313 may 3, 2013 05:00

    Hi Bala,

    If I interpreted the statement correctly, then you are wanting fill the digits left of the decimal point to four characters, so 12.345 becomes 0012.345.

    The best way to achieve this is by using a processor of Expression (see the online help for details of full syntax). Assuming that the input attribute is called 'col1' then the following expression should lead to the desired result:

    substr ('000' | col1, indexof (col1, ".") - 1).

    Kind regards
    Nick

  • Need help in writing the SQL CASE or DECODE statement

    Hi experts,

    I need to write a SQL select order_num, cntry_cde, prod_id and Qty by joining order_num on PROD_ORDER and PROD_ORDER_TXT.

    Here is my sample data

    PROD ORDER_
    order_num Prod_id Qty cntry_cde
    100 US A1 5
    101 US 10 A2
    102 IN A3 4
    103 TO THE A4 9
    104. IN A5 3

    PROD ORDER_TXT_
    cntry_cde Prod_id order_num
    100 US A1
    101 US A2
    102 NZ A3
    103 TO THE A4
    A5 104

    Here's the requirement,

    (1) if the cntry_cde in PROD_ORDER is the same as cntry_cde in PROD_ORDER_TXT then select PROD_ORDER.cntry_cde (orders 100, 101, 103)
    (2) if they are different, choose PROD_ORDER_TXT (order 102, to THE NZ <>) country code
    (3) if they are different and PROD_ORDER_TXT.cntry_cde is null, I can't use it like cntry_cde in my report (order 104). It happenend just because of bad data to the source.
    I can't avoid it. Then just use the cntry_cde of PROD_ORDER

    Expected results
    100 US A1 5
    101 US 10 A2
    102 NZ A3 4 - changed in NZ
    103 TO THE A4 9
    104. IN A5 3 - IN retained as PROD_ORDER_TXT.cntry_cde is null


    instructions for creation and insertion of sample table are lower than

    create the table prod_order
    (number of order_num,
    cntry_cde CHAR (2),
    prod_id VARCHAR2 (6).
    number of quantity)

    create the table prod_order_txt
    (number of order_num,
    cntry_cde CHAR (2),
    prod_id VARCHAR2 (6))

    insert into prod_order values (100, 'WE', 'A1', 5);
    insert into prod_order values (101, 'WE', 'A2', 1);
    insert into prod_order values (102, ' to THE ', 'A3', 4);
    insert into prod_order values (103, ' to THE ', 'A4', 9);
    insert into prod_order values (104, 'IN', 'A5', 3);



    insert into prod_order_txt values (100, 'WE', 'A1');
    insert into prod_order_txt values (101, 'WE', 'A2');
    insert into prod_order_txt values (102, 'NZ', 'A3');
    insert into prod_order_txt values (103, ' to THE ', 'A4');
    insert into prod_order_txt values (104, 'A5', NULL);

    commit;

    Thank you for your help in advance

    Published by: manon March 28, 2012 13:39
  • Case statements with AND

    Hi all.

    I use a case statement to represent the values for different regions in a command prompt. I'm having some difficulties, with the values in the case statement. Here is an example of a simplified and shortened my code version.

    CASE

    WHEN 'Region '. "" Region name "="A"THEN"AMERICA ".

    WHEN 'Region '. "" Region name "= 'B' THEN 'CHINA '.

    WHEN 'Region '. "" Region name "= 'C' THEN 'EUROPE '.

    WHEN 'Region '. "' Name of the region ' = 'A' AND 'B' AND 'C' THEN 'GLOBAL '.

    END

    My error when I use it in my statement. The formula is accepted, however, all the values are displayed in my guest except 'GLOBAL '.

    How can I be able to assign a "GLOBAL"value in my guest? ".

    Jagadekara I think that you do not get the point. Any given row retrieved from a data source cannot have all three at one point values!

    AJ was trying to tell you, is that your CASE logic has no sense at all.

  • When case statement?

    Hi, I have a question: if my case when the statement is correct. "Œuvre" is an alias for the database.

    and BOX WHEN "Work" =: WORK THEN END of TO_CHAR (0) of OTHER 'work' = NVL ('Work' =: WORK, '0')

    Hello TKS -.

    Here is the general syntax for a CASE statement in OBIEE:

    CASE 'Table name' WHEN. "' column name ' = @{variable presentation} THEN"table name ". "' column name ' ELSE '0' END

    Some things to note:
    (1) ' table name '. ' column name ' is the logical naming convention used by OBIEE. You can get these values automatically simply by clicking on the column on the left side of the screen
    (2) variable presentation can be defined using the guests of dashboard, where the user can select a value and have the report reflect these changes.
    (3) to put single quotes around a value is a string, not a number. I guess this based on your post.

    If you use NVL function on the above statement, use the following:

    IFNULL (BOX "Table name" WHEN. "column name" = @{variable presentation} THEN 'table name' "." column name"END ELSE ' 0 ', ' 0')"

    I hope this helps and please assign points if you found it useful!

    Kind regards
    Jason

  • Engine using a state machine control logic

    Hello

    I'm trying to implement motor control using the logic of the state machine. My requirement is simple. I have a voltage from data acquisition value that corresponds to the couple (initial value = 5). I need my feeding motor a positive (right-hand rotation) and negative (counterclockwise rotation) speed depending on whether the value of this tension is between the top (7 V) and the lower thresholds (3 V).

    In other words, the motor starts to turn in a clockwise direction at the outset; the voltage is declining, as soon as we get to <= 3="" v,="" it="" changes="" direction="" and="" moves="" counterclockwise="" till="" it="" hits="">= 7 V, then changes direction again and this repeatedly for, say user-defined number of cycles. I tried to write this logic, and when I run the program it starts well, is to see the first time, entry happens under a low threshold, changes direction but oscillates at the same position. He won't until > = 7 V.

    I enclose the code for your reference. Logical machine state in queue can be of any help? Also, can I present a State in which after that user-defined cycles are more the engine back to a position where the voltage is 5 V.

    Thank you very much.

    Ravens fan is OK.  You need to know which direction you are moving before deciding what to do comparison.  Look at this simple diagram that shows how to use a shift register to keep track of which direct that you use.

  • How to aggregate categories Case statement to get a number of each

    I would like to summarize this query, a County, or the sum of each category in the case statement, please help!

    Here's a query I would like to change so he made a count (*) instead of list retail

    Select distinct
    partner, region, od. ORDER_AFFILIATE_NAME,
    Oh.external_order_number,
    Ain.get_g1 (queue_type) offers,
    Case
    When disp.category = 100 Then 'ORDER'
    When disp.category = 200 Then 'ACCESS'
    When disp.category = 300 Then 'DSL'
    When disp.category = 600 Then 'IPTV'
    "When disp.category = 700 Then'INTERNET"
    When disp.category = 800 Then 'VOIP'
    End up like product_category,
    To_char(OH.created_ts, 'yyyy-mm-dd HH24:mi:ss') CREATE_DATE

    -Case when ip.offer_type = "IPDSLAM" or instr (ip.display_name, "-d") > 0
    THEN 'IP - LAN'
    ELSE 'FTTN.
    end as product_type

    Case
    When disp.state = 4 and disp.state = 9 or disp.state = 21 or 22 = disp.state then 'cancelled '.
    When disp.state = 17 then "NRFC cancelled.
    When disp.state = 7 Then 'incomplete '.
    When disp.state = 3 or disp.state = 8, then "Finish".
    When disp.state = 6 or disp.state = 10 and disp.state = 13 or disp.state = 14 then 'pending - other ".
    When disp.state = 19 disp.state = 20 then "sent".
    When disp.state = 21 or disp.state = 22 then "Cancelled - CSUS.
    When disp.state = 23 or 24 = disp.state then 'Order Confirmation '.
    When disp.state = 1 or disp.state = 2 or disp.state = 15 then "receipt".
    Another 'other '.
    End as STATE_desc



    of AIN.impl_oh_order_header oh,.
    Ain.impl_order_data od,
    DISP AIN.sncr_order_curr_disp,
    AIN.impl_package ip
    where oh.created_ts between to_date ('2013-02-04', ' yyyy-mm-dd "")
    and to_date ('2013-02-11', ' yyyy-mm-dd "")
    and oh.order_type = 'COMMAND '.
    and disp.category to (200, 300, 600, 700, 800)
    and disp.state! = '5'
    and uscs = 0
    and disp.transaction_id = oh.transaction_id
    and od. transaction_id = oh.transaction_id
    and ip.transaction_id = oh.transaction_id
    and ip.package_type = 'PACKAGE '.
    and ip.parent_package_id is null
    and ip.product_type = 'COMMAND '.

    See the answer in your other thread:
    Help, please! Need to modify this Script to do a Count (*)

  • error with the case statement use what void const query

    Hi all.

    I have found the error in the result set, and then use subqueries and cases of declaration.

    Preparation for example.

    2 examples of tables creation.
    CREATE TABLE T1 
    AS
    (
        SELECT 1 ID , 1 F1 FROM DUAL
        UNION 
        SELECT 2 ID , 1 F1 FROM DUAL
        UNION 
        SELECT 3 ID , 1 F1 FROM DUAL
    ) ;
    
    CREATE TABLE T2
    AS
    (    
        SELECT 2 ID FROM DUAL
        UNION 
        SELECT 3 ID FROM DUAL
    ) ;
     
    This statement returns NULL in subquery
    SELECT 
    T1.ID, TT2.ID , TT2.ISBUG AS NO_BUG 
    FROM T1 
    LEFT JOIN
    (
    SELECT ID , -1 ISBUG FROM T2
    )TT2
    ON T1.ID = TT2.ID
    WHERE TT2.ID IS NULL
     
    But this statement (with operator CASE) does NOT return null in subquery
    SELECT 
     CASE  WHEN 1 = 1 THEN 1 END AS C1,
    T1.ID, TT2.ID , TT2.ISBUG 
    FROM T1 
    LEFT JOIN
    (
    SELECT ID , -1 ISBUG FROM T2
    )TT2
    ON T1.ID = TT2.ID
    WHERE TT2.ID IS NULL
     
    Why?

    Oracle 11.2.0.2.0

    Published by: 927438 on 13.04.2012 03:27

    Published by: 927438 on 13.04.2012 03:31

    Maybe it is related to this one

    outer join of 11g with case - strange results statement.

    seems to be a bug

  • Case for Satellite click on L9W Mini-B

    Was looking for a case for Mini click for a while, all I could find were netbook 10 "business that were too big. Came across this Case Logic

    It's a perfect fit, Tablet is very tight when zipped. On the inside of the case is a stand which folds that you could cut it with scissors, but the Tablet fits anyway so I don't bother, it adds extra padding.

    Hope it will be useful to others. Mine was bought on Amazon UK for £2.95, but I don't know there is no other sellers in the world.

    Message has been modified: commercial link has been removed

    Thanks for sharing!

  • How to find valid cases in the truth table?

    Hello

    I am using a truth table to select the next case in my state machine. The number of possible cases is 256 with a set of 8 input of Boolean values. The following is a generic example.

    Obviously, I don't need the conditions of passage, but how to weed them out of the table?

    0          1          2          3          4          5          6          7          8          9          10        11        12        13        14            15in house?            F          T          F          T          F          T          F          T          F          T          F          T          F          T          F            Tpassed test?       F          F          T          T          F          F          T          T          F          F          T          T          F          F          T            Tscrapped?          F          F          F          F          T          T          T          T          F          F          F          F          T          T          T            T in inventory?      F          F          F          F          F          F          F          F          T          T          T          T          T          T          T            T

    The numbers along the top refer to the result of the code just before the structure case in the attached vi.

    Tay

    jcarmody wrote:

    I often do.  Take each of your eight Boolean and consolidate them in a table, convert the table number and select your case on that based on the number.  Thus, if the first fifth suite and boolean (from above) are true, you have 25 case (10011000 = 25).  You can have a case manage multiple values, separate them with a comma in the selector.  It will make you famous.

    I do the same thing, but the value of the radix of the binary display case.

  • Master/slave event Structure vs. State Machine

    Hello

    First some background to the question (skip this paragraph if you are simply interested in the question). I'm relatively new to Labview, after only a few months of coding with Labview and LabVIEW Core 1. Being one of the only people in the company who now knows Labview I have been challenged with the creation of a relatively complex application that will perform a selected ten or to view different tests with customizable options, display, analyze and deliver and automate reports.

    For the application I am writing I need a GUI with several screens (I achieve with tabs), initially I tried this code with the structures of the event within a machine to States (but as you probably know this was fundamentally flawed, that you can't put structures of the event within the structures of the case) (, or structures of the event), but from here, I spent several hours of searching the best alternatives.

    So my Question is: would recommend to use a master-slave (with the structure of the event and the State of computer, respectively), or simply use to continually voting machine status?

    (Keep in mind I'm going to use this as part of a larger facility of producer/consumer.)

    Thanks in advance,

    Joshua Walker.

    I use a case in my state machine specifically for checking to GUI events.  It is usually a "Idle" State or a specific State to 'check events.  I can also set the time-out programmatically by using a register shift, just in case I need to do a quick check (some small timeout) or wait for a user to press a button (timeout is - 1).

  • Having a strange action case structure on a timed loop.

    A resolved question yesterday, lead to a new problem. In this VI, I have a timer that triggers an external meter. The counter "counts" from 1 to 24, each with an action at a given time. However, once I got the timer and counter work, I found that the Boolean trigger remained on the hour enitre, and my action was repeated several times instead of only one. So, I changed the counter count 0.1 each interval, rather than 1.0, thinking that it would only allow my State business to operate for a shorter window. However, when I run the VI, the case of the State are active in the meantime, not at the interval. For example, cases of stae 2 is active between 1.5-2.5 iteration and iteration throguh 2.5 3.5 State case 3 is active. Can anyone suggest how to get either 1) better display resolution on the evidence of the State of th or 2) another way to get the Boolean value for just a few seconds?

    Thank you, Lynn.  Yep, I tried that (at least the half of it.)  I opened it in my first version, which is being 8.5.1.  I don't think to check in the dialog changes not saved, however.  I feel kind of sheepish having never tried that before.

    Well, here is my interpretation of what was asked for... I had to make a few assumptions, namely that the 'timed loop' refers to the while loop that runs at a defined interval, and that "triggers" are just the Boolean flags.

    I hope that this at least partially answered questions?

    Jim

  • creation of structures: state machine with controls

    Hello, I wonder if someone can help me with something. I have a sequence, followed by the event structure / while loop.

    someone can help me. I want to create a STATE MACHINE.

    Here's a basic outline of the current structure, I. and this is what I want it to be. I wonder if its possible and how.

    I'm using labview 7.0.

    Thank you

    This is what I want?

    I looked at your Executive VI.  I don't have an easy way to save in LV 7 now so I'll try to describe in words how I would approach this mess.

    I think it can be done with two loops, a structure of the event, a case structure and not global or local variables.  In fact, there is probably some small business structures and lines inside some of the case, but nothing like as layers of ~ 12 nesting, you're struggling now.

    Look at the design model of producer/consumer (events) as a starting point.

    The loop of producer (event loop) will have the structure of the event.  It will be a case for each control that requires immediate action.  Those that I could identify: get telemetry, side, open Journal printing, abandon, press tank Mode (?) Temp tank (?), Scan, Stop, wait, Step (?) unique, continue and Execute. Most of the buttons must be set on the mechanical action of locking and placed terminals in the case of the event appropriate. So no local population is necessary to reset them.  Those with (?) have no event.  You can have a case of timeout to display Date and time, eliminating which (painful to my eyes) loop.  I don't know about the other stuff in the case of a timeout, but most likely, it is up to the other loop.  If the room 1, 2,... buttons change during trips, they may also need event.  Inside of each event is exactly one element: the Enqueue function.  Create an enum command and make it a typedef. Enqueue this enum value. The queue will be read in the loop of consumer where all the action happens.

    The consumer is your state machine. It has a Dequeue function to get a new order for the structure of the event.  It has several shift registers to transfer data from one case to the other.  These removes your global and local variables.  I'd shift for each of the following registers: the State (typedef enum), cluster of error, temperature (table), pressure (table), results (table), Stat results (table grapes) and a big cluster Indicators_Flags (typedef).  The cluster Indicators_Flags everything that is in the cluster you initialize in the black image sequence (and then never reuse) would have more all indicators except the berries in Maj separate records as well as all your globals and no status indicator, you might need.

    The structure of matter is the heart of the state machine.  All shift registers through it.  It will be the case for what the program does.  Everything in this black initialization setting in about 15 cases of Init.  The while loop to the right of the boot image goes away, but the case inside to become some of the cases of the state machine.  Chassis temperature cycling code goes into 1-3 cases. Mode code pump and read the pressure of your case of timeout event are 1-3 cases.  Code of telemetry: 2 cases.  Print the Page before: 1 case.  Excel code.  Abandonment of code.  Temperature and pressure cycling code of main program: 5-20 cases.  Graphics, record in file: more cases.  Break: 1-2 cases.

    I would like to make a list on paper anyway, you think that you may need and allows to create a typedef enum to control cases.  By making a typedef, it is easy to change without running all over the code looking for the constant in all cases of change.  Enum names will appear on the structure of matter as strings.  Create the loop, shift registers and the structure of the case.  Moving is part of both the original thread can duplicate the case until you have a case for each value in the enumeration of the State.  (Do not use the case of the mark for each value option because it will empty cases that you will then need to wire through.)

    Then copy code from various places in your existing code in the case in the new VI.  Try to avoid copying inhabitants that it will create new controls.  Name bundle to get data in and out of the big bend cluster registry and use ungroup by name.  This provides a free documentation of the data used.

    Check in a month when you have other problems. This will not be a quick fix.  But it will be useful to have a program that works and is easy to manage.

    Lynn

Maybe you are looking for