SELECT statement and decode.

Hi all.
I'm working with decode them but I get the wrong result. the following code shows the first not the U04 U02, U03 U01, I want to show all u01 until
U04 here is the code.
SELECT id, id2 ,
SUM(DECODE(id,55,AMOUNT,0)) TP,
SUM(DECODE(ID,56,AMOUNT,0)) COMP
FROM table
where id2 in('u01','uO2','u03','u04')
AND ID IN ('55','56')
GROUP BY ID,ID2
any suggestion?


Sarah

You do not have all the lines where id2 in('u03','u04') and in id ('55 ', ' 56')

Tags: Database

Similar Questions

  • SELECT statement and cursor

    Hi all

    Given the following code:
         TYPE option_rec IS RECORD
         (
            value varchar2(3),
            label varchar2(255)
         );
     TYPE option_list_t IS TABLE OF option_rec;
     
    
     FUNCTION get_object_list
        RETURN option_list_t
        PIPELINED
        DETERMINISTIC
      IS
            tmp option_rec;
      BEGIN
     
            tmp.value:='1';
            tmp.label:='foo';
            PIPE ROW(tmp);
     
            tmp.value:='2';
            tmp.label:='bar';
            PIPE ROW(tmp);
           RETURN;
      END get_object_list;
     
      FUNCTION generate_select(selected_value in varchar2)
        RETURN sys_refcursor
      IS
         ret sys_refcursor;
      BEGIN
        open ret for
             select value as value,
                    '(' || value || ') ' || label as label,
                    case value
                       when selected_value then
                          'selected'
                       else
                          ''
                    end as selected
               from table(get_object_list);
        return ret;
      END generate_select;
     
    I can't succeed runnig this query:
    select *
    from cursor(generate_select('2'))
    I have the following error:
    ORA-00933: "SQL command not properly ended"
    What's wrong?
    I run on Oracle 10 g 2

    With a function in defined pipeline looking for documentation for the SCOREBOARD operator
    You must Select (TABLE (get_object_list ()) where... )
    Concerning

    Etbin

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/tuning.htm#sthref2351

    Edited by: Etbin 27 April 2009 19:09

  • Clause of update with a nested select statement, and a weird error

    Hi all!

    I am trying to execute the following SQL clause:

    setting a day of f_kontakti kon set ikaluokka =
    (
    Select ikal of
    (
    Select kontakt_ik, ikaluokka_gen(1,ai2.pvm,ai.pvm) as ikal
    of f_kontakti k
    Join the a on (k.asiakas_ik = a.asiakas_ik) d_asiakas
    Join d_aika HERE on (a.synt_aika_ik = ai .aika_ik)
    Join d_aika ai2 on (k.aika_ik = ai2.aika_ik)
    where k.kontakt_ik = kon.kontakt_ik
    ) salt
    )

    It works very well on our test database (10.2.0.1.0), but when I try to run it on our production database (10.2.0.4.0), it gives the following error:
    ORA-00904: "KON". "" KONTAKT_IK ": invalid identifier

    The nested select works fine when I run it separately (without where clause of course, because then it does not really anywhere point) on two databases, but for some reason, the full update only fails on the production system. Any ideas on what could cause this?

    Kind regards
    Erik

    You can run it without selecting it nesting.

    Like this

    update f_kontakti kon
    set ikaluokka=
     (
      select ikaluokka_gen(1,ai2.pvm,ai.pvm) as ikal
      from f_kontakti k
      join d_asiakas a on (k.asiakas_ik=a.asiakas_ik)
      join d_aika ai on (a.synt_aika_ik=ai.aika_ik)
      join d_aika ai2 on (k.aika_ik=ai2.aika_ik)
      where k.kontakt_ik=kon.kontakt_ik
    );
    

    or even shorter

    update f_kontakti kon
    set ikaluokka=
     (
      select ikaluokka_gen(1,ai2.pvm,ai.pvm) as ikal
      from d_asiakas a on (kon.asiakas_ik=a.asiakas_ik)
      join d_aika ai on (a.synt_aika_ik=ai.aika_ik)
      join d_aika ai2 on (kon.aika_ik=ai2.aika_ik)
      );
    
  • passing multiple values from the query in the select statement of the procedure

    I am collecting IDS to select education agreement from the date of rental values and then I would pass the result of the query in the statement select to get the result.
    data type for the contract id is of type varchar and date of rental there is more than one id to contract for most of the time. Help, please. Thank you

    CREATE OR REPLACE PROCEDURE abstract_menu (p_letting   IN     VARCHAR2,
                                               p_results      OUT SYS_REFCURSOR)
    IS
       v_contractId   VARCHAR2 (40);
    
    SELECT lcontid
      INTO v_contractId
      FROM letprop
     WHERE datestat IS NOT NULL AND letting = p_letting AND letstat <> 'R';
    
    
    BEGIN
       OPEN p_results FOR
            SELECT DISTINCT
                      SUBSTR (l.letting, 3, 2)
                   || '-'
                   || SUBSTR (l.letting, 5, 2)
                   || '-'
                   || SUBSTR (l.letting, 1, 2)
                      lettingdate,
                   l.lcontid contractid,
                   SUBSTR (q.cprojnum, 1, 10) projectnumber,
                   DECODE (TRIM (MIN (j.route)), NULL, 'N/A', TRIM (MIN (j.route)))
                      routenumber,
                   L.DATESTAT statusdate,
                   L.LETSTAT lettingstatus,
                   (q.cdescr) jobdescription,
                   INITCAP (q.clocat1 || q.clocat2) LOCATION
              FROM vendor v,
                   vendaddr r,
                   letprop l,
                   planhold p,
                   proposal q,
                   project j,
                   propproj k,
                   bidlet bd
             WHERE     v.vendor = r.vendor
                   AND k.contid = q.contid
                   AND k.pcn = j.pcn
                   AND l.lcontid = k.contid
                   AND p.vendor = v.vendor
                   AND l.letting = p.letting
                   AND l.lcontid IN v_contactid  "**************This is where I would like to pass the contract id from the above select statement***********'"
                   AND l.CALL = p.CALL
                   AND r.addrnum = p.billto
                   AND bd.letting = l.letting
          GROUP BY q.cdescr,
                   q.clocat1,
                   q.clocat2,
                   bd.letting,
                   l.letting,
                   l.lcontid,
                   q.cprojnum,
                   L.LETSTAT,
                   L.DATESTAT
          ORDER BY lettingdate;
    
    end;

    user9196150 wrote:
    AND l.lcontid IN v_contactid ' * this is where I would like to pass the id of the select statement above contract * ""»

    CREATE OR REPLACE PROCEDURE abstract_menu (p_letting   IN     VARCHAR2,
                                               p_results      OUT SYS_REFCURSOR)
    IS
    BEGIN
       OPEN p_results FOR
            SELECT DISTINCT
                      SUBSTR (l.letting, 3, 2)
                   || '-'
                   || SUBSTR (l.letting, 5, 2)
                   || '-'
                   || SUBSTR (l.letting, 1, 2)
                      lettingdate,
                   l.lcontid contractid,
                   SUBSTR (q.cprojnum, 1, 10) projectnumber,
                   DECODE (TRIM (MIN (j.route)), NULL, 'N/A', TRIM (MIN (j.route)))
                      routenumber,
                   L.DATESTAT statusdate,
                   L.LETSTAT lettingstatus,
                   (q.cdescr) jobdescription,
                   INITCAP (q.clocat1 || q.clocat2) LOCATION
              FROM vendor v,
                   vendaddr r,
                   letprop l,
                   planhold p,
                   proposal q,
                   project j,
                   propproj k,
                   bidlet bd
             WHERE     v.vendor = r.vendor
                   AND k.contid = q.contid
                   AND k.pcn = j.pcn
                   AND l.lcontid = k.contid
                   AND p.vendor = v.vendor
                   AND l.letting = p.letting
                   AND l.lcontid IN (
                                     SELECT  ll.lcontid
                                       FROM  letprop ll
                                       WHERE ll.datestat IS NOT NULL AND ll.letting = p_letting AND ll.letstat  'R'
                                    )
                   AND l.CALL = p.CALL
                   AND r.addrnum = p.billto
                   AND bd.letting = l.letting
          GROUP BY q.cdescr,
                   q.clocat1,
                   q.clocat2,
                   bd.letting,
                   l.letting,
                   l.lcontid,
                   q.cprojnum,
                   L.LETSTAT,
                   L.DATESTAT
          ORDER BY lettingdate;
    
    end;
    /
    

    SY.

  • creating a table from a select statement

    is it possible to run a select statement that creates a table based on the statement of execution? in MSSQL I can include 'in {tablename}"in a select statement and it will automatically create the table field names / on the fly?

    I know I can run "insertion in {tablename} select * from foo" to fill an existing table, but I want something that creates the table as well.
    create table 
    as select ...
    

    Is that what you are looking for?

    Nicolas.

  • MX:button selected state

    I work on a bug https://bugs.adobe.com/jira/browse/SDK-16197 and account try to test a solution that I have developed, and now I realize that I don't know when a button changes to 'selected' State  I placed a trace statement to the Set accessor for the selected function, and I couldn't figure out how to get this fire.  I tried to click, tab to her so that she had developed, using the space bar while he had the focus.

    If we consider a selected button?

    A button must have toggle = true in order to stay in the selected state and will send a CHANGE event when you change the selected property.

    Alex Harui

    Flex SDK Developer

    Adobe Systems Inc..

    Blog: http://blogs.adobe.com/aharui

  • Select statements

    Hey,.
    I am new to use apex 4.0 and I am trying to create a select statement and I get an error. The error is
    "ORA-01427: einreihig subquery returns more than one line.

    My select statement is:

    Select * from XXMFG_CHANGE_FORM_SIGNOFF where item_number = (select item_number XXMFG_CHANGE_FORM_master where final_signoff_value IS null)

    Thank you

    Swens,

    I bet that if you ran

    select item_number from XXMFG_CHANGE_FORM_master where final_signoff_value IS null
    

    in the SQL workshop, you get several results back. This is what means this error. So you need to either set your logic to return a single element or change your = a in. It depends on what you want your code to do.

    select *
    from XXMFG_CHANGE_FORM_SIGNOFF
    where item_number in (select item_number from XXMFG_CHANGE_FORM_master where final_signoff_value IS null)
    

    Whatever it is, it is a problem SQL, not an APEX one.

    -David

  • Formatting for a select statement

    I am trying to include formatting in a select statement.

    The data, I'm pulling compared to the SSN for a unique value. The problem is that the SSN is formatted with dashes in a table and not in the other.

    Example:


    Table 1
    Name SSN
    John 400-30-8745
    Mary 348-00-4093



    Table 2
    Name SSN
    John 400308745
    Mary 348004093



    What I would do is:

    Select * into Table1, Table2 where table1.ssn = table2.ssn

    However, I am unable to do so due to the formatting.

    Thxs!

    It will not replace the data in the database because it is a SELECT statement and not a DML (INSERT, UPDATE, DELETE) statement. You can also consider putting a function based on this column in table1 index to facilitate this request. However, it depends on many factors and because we do not know the versions, estimated use, how many times the table is updated, etc., we can say with certainty whether this can help or not. An example would be:

    CREATE INDEX TABLE1_SSN_FBIDX ON TABLE1(REPLACE(SSN,'-'))
    
  • The execution of a select statement

    I want to run a select statement and show extract it result in table view (multiple records) how do?

    Add a button to the form created by my suggestions, create a WHEN-BUTTON-PRESS-trigger for her and the code

    GO_BLOCK('MYBLOCK');
    EXECUTE_QUERY;
    
  • Maximum number of DECODE in a select statement

    Is there a limit on the number of Decodes a statement select SQL can handle?

    I ran the following statement and it's what gives an error after the 3rd DECODE.

    Any idea of a solution is much appreciated.

    Thank you.




    SQL > SELECT
    2 NAME, DIRECTION. DIRECTORATE_ID, AFC,
    V_ADJUSTMENT_ACTUAL_RESULT 3. FUND, V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE,
    4 ADJUSTMENT_PCT, V_ADJUSTMENT_ACTUAL_RESULT.FY,
    5 DECODE (V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE, "FD", SUM (PP21 PP22 + PP23 + PP24 + PP25 + PP26 + DP1 + PP
    2 PP3 + + PP4 PP5 + + PP6 PP7 + + PP8 PP9 + PP10 + PP11 + PP12 + PP13 + PP14 + PP15 + PP16 AND PP17 + PP18 + PP19 + PP20)) AS FD,
    6 DECODE (V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE, 'FR', SUM (PP21 PP22 + PP23 + PP24 + PP25 + PP26 + DP1 + PP
    2 PP3 + + PP4 PP5 + + PP6 PP7 + + PP8 PP9 + PP10 + PP11 + PP12 + PP13 + PP14 + PP15 + PP16 AND PP17 + PP18 + PP19 + PP20)) AS EN.
    7 DECODE (V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE, "OD", SUM (PP21 PP22 + PP23 + PP24 + PP25 + PP26 + DP1 + PP
    2 PP3 + + PP4 PP5 + + PP6 PP7 + + PP8 PP9 + PP10 + PP11 + PP12 + PP13 + PP14 + PP15 + PP16 AND PP17 + PP18 + PP19 + PP20)) THAN OD.
    8 DECODE (V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE, 'OR', SUM (PP21 PP22 + PP23 + PP24 + PP25 + PP26 + DP1 + PP
    2 PP3 + + PP4 PP5 + + PP6 PP7 + + PP8 PP9 + PP10 + PP11 + PP12 + PP13 + PP14 + PP15 + PP16 AND PP17 + PP18 + PP19 + PP20)) AS OR.
    9 DECODE (V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE, "FF", SUM (PP21 PP22 + PP23 + PP24 + PP25 + PP26 + DP1 + PP
    2 PP3 + + PP4 PP5 + + PP6 PP7 + + PP8 PP9 + PP10 + PP11 + PP12 + PP13 + PP14 + PP15 + PP16 AND PP17 + PP18 + PP19 + PP20)) LIKE FF
    10 FROM
    11. THE STAFFING. V_ADJUSTMENT_ACTUAL_RESULT,
    12. THE STAFFING. ADJUSTMENT,
    13. THE STAFFING. DIRECTION OF
    14. WHERE
    15. THE STAFFING. V_ADJUSTMENT_ACTUAL_RESULT. DIRECTORATE_ID = STAFFING. DIRECTORATE GENERAL. DIRECTORATE_ID
    16 AND THE WORKFORCE. SETTING. DIRECTORATE_ID = STAFFING. V_ADJUSTMENT_ACTUAL_RESULT. DIRECTORATE_ID

    17 GROUP OF
    DIRECTORATE.NAME 18,
    19 DIRECTION. DIRECTORATE_ID,
    20 V_ADJUSTMENT_ACTUAL_RESULT. AFC,
    21 V_ADJUSTMENT_ACTUAL_RESULT. FUNDS,
    22 V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE,
    23 SETTING. ADJUSTMENT_PCT,
    24 V_ADJUSTMENT_ACTUAL_RESULT.FY
    25 ORDER BY
    DIRECTORATE.NAME 26,
    27 DIRECTION. DIRECTORATE_ID,
    28 V_ADJUSTMENT_ACTUAL_RESULT. AFC,
    29 V_ADJUSTMENT_ACTUAL_RESULT. FUNDS,
    30 V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE,
    31 SETTING. ADJUSTMENT_PCT,
    32 V_ADJUSTMENT_ACTUAL_RESULT.FY;
    DECODE (V_ADJUSTMENT_ACTUAL_RESULT. FUND_TYPE, 'OR', SUM (PP21 PP22 + PP23 + PP24 + PP25 + PP26 + DP1 + PP2 + PP3

    ERROR on line 8:
    ORA-00923: THE KEYWORD not found where expected

    Published by: user551757 on January 28, 2009 13:17

    The last line of your code is oncorrect.
    Or is a reserved word in Oracle.
    Try this code.
    Kind regards.
    Salim.

    SELECT   NAME, directorate.directorate_id, afc,
             v_adjustment_actual_result.fund,
             v_adjustment_actual_result.fund_type, adjustment_pct,
             v_adjustment_actual_result.fy,
             DECODE (v_adjustment_actual_result.fund_type,
                     'FD', SUM (  pp21
                                + pp22
                                + pp23
                                + pp24
                                + pp25
                                + pp26
                                + pp1
                                + pp2
                                + pp3
                                + pp4
                                + pp5
                                + pp6
                                + pp7
                                + pp8
                                + pp9
                                + pp10
                                + pp11
                                + pp12
                                + pp13
                                + pp14
                                + pp15
                                + pp16
                                + pp17
                                + pp18
                                + pp19
                                + pp20
                               )
                    ) AS fd,
             DECODE (v_adjustment_actual_result.fund_type,
                     'FR', SUM (  pp21
                                + pp22
                                + pp23
                                + pp24
                                + pp25
                                + pp26
                                + pp1
                                + pp2
                                + pp3
                                + pp4
                                + pp5
                                + pp6
                                + pp7
                                + pp8
                                + pp9
                                + pp10
                                + pp11
                                + pp12
                                + pp13
                                + pp14
                                + pp15
                                + pp16
                                + pp17
                                + pp18
                                + pp19
                                + pp20
                               )
                    ) AS fr,
             DECODE (v_adjustment_actual_result.fund_type,
                     'OD', SUM (  pp21
                                + pp22
                                + pp23
                                + pp24
                                + pp25
                                + pp26
                                + pp1
                                + pp2
                                + pp3
                                + pp4
                                + pp5
                                + pp6
                                + pp7
                                + pp8
                                + pp9
                                + pp10
                                + pp11
                                + pp12
                                + pp13
                                + pp14
                                + pp15
                                + pp16
                                + pp17
                                + pp18
                                + pp19
                                + pp20
                               )
                    ) AS od,
             DECODE (v_adjustment_actual_result.fund_type,
                     'OR', SUM (  pp21
                                + pp22
                                + pp23
                                + pp24
                                + pp25
                                + pp26
                                + pp1
                                + pp2
                                + pp3
                                + pp4
                                + pp5
                                + pp6
                                + pp7
                                + pp8
                                + pp9
                                + pp10
                                + pp11
                                + pp12
                                + pp13
                                + pp14
                                + pp15
                                + pp16
                                + pp17
                                + pp18
                                + pp19
                                + pp20
                               )
                    ) AS orr,
             DECODE (v_adjustment_actual_result.fund_type,
                     'FF', SUM (  pp21
                                + pp22
                                + pp23
                                + pp24
                                + pp25
                                + pp26
                                + pp1
                                + pp2
                                + pp3
                                + pp4
                                + pp5
                                + pp6
                                + pp7
                                + pp8
                                + pp9
                                + pp10
                                + pp11
                                + pp12
                                + pp13
                                + pp14
                                + pp15
                                + pp16
                                + pp17
                                + pp18
                                + pp19
                                + pp20
                               )
                    ) AS ff
        FROM staffing.v_adjustment_actual_result,
             staffing.adjustment,
             staffing.directorate
       WHERE staffing.v_adjustment_actual_result.directorate_id =
                                               staffing.directorate.directorate_id
         AND staffing.adjustment.directorate_id =
                                staffing.v_adjustment_actual_result.directorate_id
    GROUP BY directorate.NAME,
             directorate.directorate_id,
             v_adjustment_actual_result.afc,
             v_adjustment_actual_result.fund,
             v_adjustment_actual_result.fund_type,
             adjustment.adjustment_pct,
             v_adjustment_actual_result.fy
    ORDER BY directorate.NAME,
             directorate.directorate_id,
             v_adjustment_actual_result.afc,
             v_adjustment_actual_result.fund,
             v_adjustment_actual_result.fund_type,
             adjustment.adjustment_pct,
             v_adjustment_actual_result.fy;
    
  • Skip and capture the Oracle SQL record dirty in a select statement

    Hello

    I have the Oracle Oracle 11.2.0.4 database when I run a select query.

    Question:

    10 columns have given Date format. When I try to execute this query into a FROG he says, a month not valid. Since the records are billion in nature, I am not able to know which line has this problem.

    Is there a way I can capture the failed row and add it to other tables and continues with the select statement regardless of this error

    OK, you have several TO_DATE functions fed a string that is built on the fly.  At least part of the time, the chain that is built does not match the date format mask used.

    For example:

    TO_DATE (SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID), 0, 8). » -'|| SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. (LAST_SUBMITTED_ON_DTTM_WID), 9, 6), "YYYYMMDD-HH24MISS")

    "SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' does not have a string where characters 5-6 are in the range 01-12.  You'll have to do an analysis on this column.  From its data and how that is managed by to_char.  What ARE the data type of ' SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' and what is a typical value?

    As others have said, this is simply an impossibility for a column of a table to actually have invalid month (or day, or year, or hour or minute or second).  ONLY, you get this error during the conversion of a string to a date with the TO_DATE function.

  • There are two select statement, which are as follows: 1) select project id, the name of ppm.pm_projects project_name and request_id 2) select id, name from request_type_name to kcrt_request_details. There is a column called entity that allows you to store

    There are two select statement, which are as follows: 1) select project id, the name of ppm.pm_projects project_name and request_id 2) select id, name from request_type_name to kcrt_request_details. There is a column called entity that can store a value i.e. project or request. I want to write a select statement containing a condition that is if the entity name is project and then run the select statement 1 otherwise, if the name of the entity's request, then run the select statement 2. All this must be written in a select statement. Can someone help me how to write this select statement type.

    Hello

    Hello

    2726057 wrote:

    ... There is a column called entity that can store a value i.e. project or request. ...

    In which table is this column?  Assuming that it is in a table called entity_table, you can do something like this:

    SELECT project AS id

    project name AS the name

    OF ppm.pm_projects

    WHEN THERE IS)

    SELECT 1

    Of entity_table

    Entity WHERE = "Project".

    )

    UNION ALL

    SELECT request_id ID

    request_type_name AS name

    OF kcrt_request_details

    WHEN THERE IS)

    SELECT 1

    Of entity_table

    Entity WHERE = 'ask '.

    )

    ;

    This does not have anything on the number of lines is entity_table, or what are the values in the column of the entity.  In other words, the query works in all cases.  If any line in entity_table entity = 'Project', then the pm_projects data will be included in the result set.  If any line in entity_table entity = 'Request', kcrt_request_details data will be included.

    I hope that answers your question.

    If this isn't the case, please post a small example 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.

    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#9362002

  • I managed to install and started to build my site, to discover my library of widgets, States and scrolling effects selections don't respond to clicking on them or open somehow. I need to reinstall and start over?

    I managed to install and started to build my site, to discover my library of widgets, States and scrolling effects selections don't respond to clicking on them or open somehow. I need to reinstall and start over?

    Are you referring to the widgets etc that you have added to pages or the actual interface of Muse?

    If it's things on the page then you most likely have an empty element above them. Do a select on your page and make sure that there are no elements that overlap your clickable items. Also make sure your clickable items are highest in your layers panel.

  • 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.

  • How to store select statements in a procedure and use it as a parameter

    I need to enter below the select statements in a stored procedure with an input parameter, business_dt_num. This parameter must be the result under the statement select and placed inside the procedure...
    select max(business_dt_num)
    from invent.dp_ca 
    If a select statement fails he must get out of the execution of the procedure and is not engaged in the next select statement. How can I cancel the execution of the procedure, if a select statement fails?
    select max(business_dt_num)
    from invent.dp_ca 
    /
    Select count (1)
    of invent.dp_ca
    where BUSINESS_DT_NUM = YYYYMMDD
    and product_id! = 0 ;
    -above and below sql account must match
    Select count (1)
    invent.dp_ca d, e invent.dp_ca_proof
    where d.BUSINESS_DT_NUM = YYYYMMDD
    and d.KEY_ID = e.KEY_ID;
    /
    exec pk_proof.pr_PopulateTaggingWorkTable_CA (yyyymmdd);
    /
    SELECT count (distinct univ_key_id) of invent.dp_ca_proof
    where business_dt_num = YYYYMMDD and proof_status! = « A » ;
    -above and below sql account must match
    Select count (0) in the invent.dp_ca_work where business_dt_num = YYYYMMDD.
    Thanks,
    Steve
    
    Edited by: steve2312 on Dec 22, 2011 12:32 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    declare
       dp_ca_count1 number;
       dp_ca_count2 number;
    begin
       select count(1) into dp_ca_count1
       from invent.dp_ca
       where BUSINESS_DT_NUM = trunc(sysdate)
       and product_id != 0;
    
       select count(1) into dp_ca_count2
       from invent.dp_ca d, invent.dp_ca_proof e
       where d.BUSINESS_DT_NUM = trunc(sysdate)
       and d.KEY_ID = e.KEY_ID;
    
       if dp_ca_count1 != dp_ca_count2 then
               raise_application_error (-20001, 'Counts do not match.');
       end if;
    end;
    /
    

Maybe you are looking for

  • Satellite L10 gets hot

    Hello world! I just bought a new laptop Satellite L10 yesterday. I noticed that he gets easily hot (but still bearable to use). Is this normal for this type of laptop? ... Thank you

  • Format a PC

    Hello I have a laptop HP pavilion g6 with windows home premium x 64 When I bought a few years ago, I don't have a windows installation CD Now, after a few years, I bought an external hard drive to back up the laptop and I want to do a format My quest

  • Material clip

    Hello I read there are 1 and 2 review material. Are there major differences between design, life of battery or any major feature? When revision 2 is out? Is it still possible that somewhere they sell me 1 revision (and I can't check the firmware)? On

  • I have installed Windows Vista SP1. I accept the conditions and the installation ends... but there is no SP1 is installed.

    Original title: I have installed Windows Vista SP1. I accept the conditions and the installation ends... but there is no SP1 is installed. I tried a few times, but the same story. I have installed Windows Vista SP1. I accept the conditions and the in

  • THE RED SCREEN ERROR

    I just bought an all in one HP Pavillion 20 I get a red error screen when you try to restore the system HP sent me the 6-disc after following all the instructions this RED SCREEN appears with the jargon of log file that I don't understand after a 1 h