Help on Select statement behavior

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
"CORE     10.2.0.4.0     Production"
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
DM_SUBSCRIPTION  table and Dm_Process_Instance_Fs_Fact  both has Consultant_Staff_Id   .
DM_SUBSCRIPTION  .Consultant_Staff_Id  =0
Dm_Process_Instance_Fs_Fact.Consultant_Staff_Id  =8436
Select Distinct Pf.Process_Instance_Id, 
                                                         Consultant_Staff_Id  
  From  Fldm.Dm_Process_Instance_Fs_Fact Pf
          LEFT OUTER JOIN  FLDM.DM_PROCESS_INSTANCE_SUB pis
             ON PIS.PROCESS_INSTANCE_ID = pf.process_instance_id
          INNER JOIN FLDM.DM_SUBSCRIPTION s
             On S.Subscription_Id = Pis.Subscription_Id
          Where Pf.Process_Instance_Id=496628
if i use fully qualified name like pf.Consultant_Staff_Id   query  is returning  correct value
but if i remove table before the column it is returning 0 .
My question is why am i not receiving error like "column ambiguously defied " ,
with out fully qualified name.what is the reason for this behaviourEdited by: vijayp on Jan 21, 2011 5:53 PM

I can not tell you why ... but I can tell you that in the Best Practice for SQL and PL/SQL white paper written by Bryn Llewellyn he advises always fully qualifying names.
So rather than wondering how to not use "best practice" use it as then the problem goes away.
Please do also keep in mind that your database version is so old it is in desupport and based on your version number could use a good patching if nothing else.

Similar Messages

  • Strange select statement behavior in start routine during extraction

    Hi, All..
    I'm receiving some odd behavior from a select statment being processed in batch mode (specifically, when run in a normal BW extractor - start routine), the select yields no results .. sy-subrc = 4 and target itab is empty.  however, when i run this same select statement in debug, i get sy-subrc = 0 and records are returned!!  I tried putting the select statement in a standard abap program & it came back successfully in both foreground & background.  something is strange when run in the BW extractor process?? anyone familiar with this?? any help is appreciated!!  Thanks!!

    Thanks everyone for the comments!
    The code is in the start routine from 0BBP_CONF_TD_1 into 0BBP_CON. 
    -The select returns records when in debug
    -I've tried running it open without the "for all entries" & it still fails in batch
    -The select works during the delta but always fails on the initial load
    The select is a join:
    DATA: BEGIN of t_JOIN1 OCCURS 0,
            CONNUM    LIKE /BI0/ABBP_CON00-BBP_CON_ID,
            CONITEM   LIKE /BI0/ABBP_CON00-BBP_COITEM,
            PONUM     LIKE /BI0/ABBP_PO00-BBP_PO_ID,
            POITEM    LIKE /BI0/ABBP_PO00-BBP_POITEM,
            ACGUID    LIKE /BI0/ABBP_PO00-BBP_ACGUID,
            SCNUM     LIKE /BI0/ABBP_SC00-BBP_SC_ID,
            SCITEM    LIKE /BI0/ABBP_SC00-BBP_SCITEM,
            REQSTR    LIKE /BI0/ABBP_SC00-BBP_REQSTR.
    DATA: END of t_JOIN1.
             SELECT a~BBP_CON_ID
                    a~BBP_COITEM
                    a~BBP_PO_ID
                    a~BBP_POITEM
                    b~BBP_ACGUID
                    c~BBP_SC_ID
                    c~BBP_SCITEM
                    c~BBP_REQSTR
               INTO TABLE t_JOIN1
               FROM /BI0/ABBP_CON00 as a
         INNER JOIN /BI0/ABBP_PO00  as b
                 ON aBBP_PO_ID  =  bBBP_PO_ID AND
                    aBBP_POITEM =  bBBP_POITEM
         INNER JOIN /BI0/ABBP_SC00  as c
                 ON bBBP_SC_ID  =  cBBP_SC_ID
                AND bBBP_SCITEM =  cBBP_SCITEM
                FOR ALL ENTRIES IN  DATA_PACKAGE
              WHERE a~BBP_CON_ID =  DATA_PACKAGE-BBP_CON_ID AND
                    a~BBP_COITEM =  DATA_PACKAGE-BBP_COITEM AND
                    a~BBP_COITEM <> 0 AND
                    b~BBP_ACGUID <> '0000' AND
                    c~BBP_SCITEM <> 0.

  • Need Help in Select Statement

    Dear gurus
    Below is my select statement. Im having problem with statement.
    the problem is that  the table vbfa  have some entries like this
    800     1400004654     10     3900012235     10     M     424,672.68
    800     1400004654     10     3900012257     10     M     137,093.36
    800     1400004654     20     3900012311     20     M     214,257.36
    800     1400004654     30     3900012412     30     M     81,248.44
    800     1400004654     30     3900012901     30     M     166,920.68
    When the select statement is run it does not fetch the data of LINE number 2 and Line number 5
    LOOP AT itab1.
        SELECT SINGLE * INTO CORRESPONDING FIELDS OF wa_vbfa
        FROM vbfa
        WHERE vbelv = itab1-vgbel
        AND posnn = itab1-vgpos
        AND vbtyp_n = 'M'.
        SELECT SINGLE * INTO CORRESPONDING FIELDS OF wa_vbrk
          FROM vbrk
          WHERE vbeln = wa_vbfa-vbeln
          AND vbtyp = 'M'.
        IF sy-subrc = 0.
            itab1-lfimg = wa_vbfa-rfmng.
           itab1-old_price = wa_vbfa-rfwrt.
           MODIFY itab1.
           ELSE.
        ENDIF.
      ENDLOOP.
    Please Help
    Regards
    Saad Nisar

    Hello Saad,
    The reason why you are not getting the 2nd and 5th entries is that, the where conditions vbelv, posnn and vbtyp_n matches for both the 1st and 2nd record where select will pick only the 1st record. The same way for 4th and 5th record. so its picking only 4th.
    So to avoid this add even vbeln in the where condition of the select query
    LOOP AT itab1.
        SELECT SINGLE * INTO CORRESPONDING FIELDS OF wa_vbfa
        FROM vbfa
        WHERE vbelv = itab1-vgbel
        AND posnn = itab1-vgpos
       AND vbeln = itab1-field           " Add the corresponding field here
        AND vbtyp_n = 'M'.
        SELECT SINGLE * INTO CORRESPONDING FIELDS OF wa_vbrk
          FROM vbrk
          WHERE vbeln = wa_vbfa-vbeln
          AND vbtyp = 'M'.
        IF sy-subrc = 0.
            itab1-lfimg = wa_vbfa-rfmng.
           itab1-old_price = wa_vbfa-rfwrt.
           MODIFY itab1.
           ELSE.
        ENDIF.
      ENDLOOP.
    Vikranth

  • Need help on select statement...

    Hi,
    I need to fetch from vbfa table those records where vbeln starts with '0800'.
    my select statement given below gives a syntax error..pl help.
    SELECT * FROM vbfa WHERE vbeln(4) = '0800'.
    vbeln(4) is not accepted and i get the message ' field vbeln(4) is unknown' ...what to do?
    thks

    Use LIKE. Please see F1 on this.
    Rob
    (changed CP to LIKE)
    Edited by: Rob Burbank on Sep 15, 2008 11:18 AM

  • Need help using Select statement  to  retrieve one record

    Hi guys, my first post so be gentle please. The basis of this fucntion is to search my dtabase using the select statement to find the record the user wants, by retrieving the name of theitem from the text box. details are then displayed on a joption message box.
    Everytime I run this program it throws an exception 'Exception: null'. Can anyone see where I am going wrong, I have only bn learning java for thepast 6 months so perhaps I am doing something wrong.
    Or perhaps there is another way for me to close the st, con, rs?
    Your help appreciated
    public void searchproducts(){
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    try{
    //creating and loading a database connection
    String dbUrl = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=db2.mdb;"; // String dbUrl = "jdbc:odbc:people";
    String user = "";
    String password = "";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection c = DriverManager.getConnection(
    dbUrl, user, password);
    int count;
    st = con.createStatement();
    rs = st.executeQuery("SELECT ItemName, Country, Yearmade, ValuePrice, Forsale FROM Collectman WHERE ItemName="+" '"+txtsearchproduct.getText()+"'" );
    while(rs.next()) {
    String ItemName = rs.getString(1);
    String Country = rs.getString(2);
    String Yearmade = rs.getString(3);
    String ValuePrice = rs.getString(4);
    String Forsale = rs.getString(5);
    JOptionPane.showMessageDialog(null, "product details are: " + ItemName + " " + Country + " " + Yearmade + " " + ValuePrice + " " + Forsale);
    //It keeps on throwing this excpetion with null
    catch (Exception e) {
    System.err.println("Exception: " + e.getMessage());
    } finally {
    try {
    if(rs != null)
    rs.close();
    if(st != null)
    st.close();
    if(con != null)
    con.close();
    } catch (SQLException e) {
    }

    And while we're waiting on that, I'll just say it's nice to see you almost got the general layout of a db call correct...that's a rare thing around here. The finally should have a try/catch round each of the close statements and not around all three in one go. If the resultset throws an exception in your version then you would fail to close either the statement or the connection.
    The second thing is, look up PreparedStatements. They're a better choice for handling SQL requiring variables than using a bog standard Statement.

  • Need help with select statement or query

    Not familiar with what to call it, but here is what i need...
    To give our analyst a better idea of warranty on some of our
    equipment, i
    would like to add to the page a column that displays if the
    device is still
    under warranty
    I currently capture the date the equipment was returned from
    repair, so what
    could i use within my select statement or query to display a
    warranty
    expiration date or display on the page...
    example :
    Returned from repair 10/20/2006 warranty expires on
    11/20/2006
    each equipment has different warranties, so i need a formula
    or something to
    say... device #1 has 60 day warranty ( so 10/20/2006 + 60days
    =
    12/19/2006 )
    I would imagine this to be a query
    Table 1 would contain the equipment type and warranty time
    Table 2 would contain the current status of the equipment
    Query would take the back from repair date + warranty =
    expiration date

    Simple. Join the two tables and create a derived column for
    the expiration date. The exact syntax is dependant on your DBMS, so
    check the manual for whichever you are using and look at the date
    functions. There will be a function that will allow you to add a
    number of date units (day, month, year, etc) to a date
    field.

  • Need help regarding SELECT statement

    Hello, first time here but need help badly.
    I been using SQL syntax with another SQL server by the following statement doesnt seem to work in Oracle database.
    SELECT firstname+" "+lastname AS fullname FROM customers
    basicially, I just want to display date from two column as one column.
    Thanks

    Oracle has pipe sign for concate
    SELECT firstname||' '||lastname AS fullname
    FROM customers;Khurram

  • Need help on Select statement/Formula

    Post Author: Krazy Kasper
    CA Forum: Data Connectivity and SQL
    My crystal report (Crystal Reports X) pulls about five thousand records/transactions. When any 2 transactions have every field the same except STATUS, I want to select from those 2 that transaction where STATUS = I.
    Appreciate any help you can provide.
    Krazy
    [email protected]

    Use LIKE. Please see F1 on this.
    Rob
    (changed CP to LIKE)
    Edited by: Rob Burbank on Sep 15, 2008 11:18 AM

  • Help with select statement

    Hello,
    My table looks similar to this, I have removed a few columns:
    table1:
    Forecast_id Forecast_name Freeze Enabled
    100 Q12009 N Y
    101 Q22009 N Y
    table2:
    forecast_id parameter_name parameter_value
    100 StartDate 01/01/2009
    100 EndDate 03/31/2009
    100 Growth % 20
    100 Retailer Walmart
    101 StartDate 04/01/2009
    101 EndDate 06/30/2009
    101 Growth % 20
    101 Retailer Walmart
    What i need to do is
    select from table 1, forecast name & freeze
    where in table2 parameter = Retailer, Parameter value = Walmart and
    Start Date = 01/01/2009 and End Date = 03/31/2009
    here is my query is there a easy way this can be done. I have used decode function in the past for similar situation for counting and grouping.
    SELECT i.FORECAST_ID,
    i.FORECAST_NAME,
    i.FREEZE_FLAG
    FROM (
    SELECT x.FORECAST_ID,
    x.FORECAST_NAME,
    x.FREEZE_FLAG
    FROM (
    SELECT A.FORECAST_ID,
    A.FORECAST_NAME,
    A.FREEZE_FLAG
    FROM GC_FORECAST A, GC_FORECAST_PARAMETERS B
    WHERE A.FORECAST_ID = B.FORECAST_ID
    AND B.PARAMETER_NAME = 'Retailer'
    AND B.PARAMETER_VALUE = 'Walmart'
    ) x, GC_FORECAST_PARAMETERS y
    WHERE x.FORECAST_ID = y.FORECAST_ID
    AND y.PARAMETER_NAME = 'StartDate'
    AND y.PARAMETER_VALUE = '01/01/2009'
    ) i, GC_FORECAST_PARAMETERS j
    WHERE i.FORECAST_ID = j.FORECAST_ID
    AND j.PARAMETER_NAME = 'EndDate'
    AND j.PARAMETER_VALUE = '03/31/2009';
    Thank you for your time and help.
    Vidhya
    Edited by: snaraya9 on Dec 5, 2008 12:03 PM
    Edited by: snaraya9 on Dec 5, 2008 12:06 PM

    Solution
    SELECT gc_forecast.forecast_id, gc_forecast.forecast_name, gc_forecast.freeze,
           gc_forecast.enabled
      FROM gc_forecast,
           (SELECT   forecast_id,
                     MAX (CASE
                             WHEN parameter_name = 'StartDate'
                             AND parameter_value = '01/01/2009'
                                THEN 1
                             ELSE 0
                          END
                         ) cond1,
                     MAX (CASE
                             WHEN parameter_name = 'EndDate'
                             AND parameter_value = '03/31/2009'
                                THEN 1
                             ELSE 0
                          END
                         ) cond2,
                     MAX (CASE
                             WHEN parameter_name = 'Retailer'
                             AND parameter_value = 'Walmart'
                                THEN 1
                             ELSE 0
                          END
                         ) cond3
                FROM gc_forecast_parameters
            GROUP BY forecast_id) gf
    WHERE gc_forecast.forecast_id = gf.forecast_id
       AND gf.cond1 = 1
       AND gf.cond2 = 1
       AND gf.cond3 = 1
    Demo
    SQL*Plus: Release 10.1.0.4.2 - Production on Ven. Déc. 5 15:34:14 2008
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connecté à :
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> /* Formatted on 2008/12/05 15:33 (Formatter Plus v4.8.8) */
    SQL> WITH gc_forecast_parameters AS
      2       (SELECT 100 forecast_id, 'StartDate' parameter_name,
      3               '01/01/2009' parameter_value
      4          FROM DUAL
      5        UNION ALL
      6        SELECT 100, 'EndDate', '03/31/2009'
      7          FROM DUAL
      8        UNION ALL
      9        SELECT 100, 'Growth', '% 20'
    10          FROM DUAL
    11        UNION ALL
    12        SELECT 100, 'Retailer', 'Walmart'
    13          FROM DUAL
    14        UNION ALL
    15        SELECT 101, 'StartDate', '04/01/2009'
    16          FROM DUAL
    17        UNION ALL
    18        SELECT 101, 'EndDate', '06/30/2009'
    19          FROM DUAL
    20        UNION ALL
    21        SELECT 101, 'Growth', '% 20'
    22          FROM DUAL
    23        UNION ALL
    24        SELECT 101, 'Retailer', 'Walmart'
    25          FROM DUAL),
    26       gc_forecast AS
    27       (SELECT 100 forecast_id, 'Q12009' forecast_name, 'N' freeze, 'Y' enabled
    28          FROM DUAL
    29        UNION ALL
    30        SELECT 101, 'Q22009', 'N', 'Y'
    31          FROM DUAL)
    32  SELECT gc_forecast.forecast_id, gc_forecast.forecast_name, gc_forecast.freeze,
    33         gc_forecast.enabled
    34    FROM gc_forecast,
    35         (SELECT   forecast_id,
    36                   MAX (CASE
    37                           WHEN parameter_name = 'StartDate'
    38                           AND parameter_value = '01/01/2009'
    39                              THEN 1
    40                           ELSE 0
    41                        END
    42                       ) cond1,
    43                   MAX (CASE
    44                           WHEN parameter_name = 'EndDate'
    45                           AND parameter_value = '03/31/2009'
    46                              THEN 1
    47                           ELSE 0
    48                        END
    49                       ) cond2,
    50                   MAX (CASE
    51                           WHEN parameter_name = 'Retailer'
    52                           AND parameter_value = 'Walmart'
    53                              THEN 1
    54                           ELSE 0
    55                        END
    56                       ) cond3
    57              FROM gc_forecast_parameters
    58          GROUP BY forecast_id) gf
    59   WHERE gc_forecast.forecast_id = gf.forecast_id
    60     AND gf.cond1 = 1
    61     AND gf.cond2 = 1
    62     AND gf.cond3 = 1;
    FORECAST_ID FORECA F E
            100 Q12009 N Y
    SQL>

  • Help on select statement

    Hi
    what i am trying to do here is if act_name is 'Designfinish' then i want to show when was the 'Finishtxt' completed and leave the Designfinish flield empty
    if act_name is 'Finishtxt' then i want to show when was the Designfinish completed and leave the 'Finishtxt' empty
    but i am getting output like this
    407614     1253393     Wo, Wo& Luk      Designfinsh      2754111     0     FSC     26-JAN-10     Ju Ben     26-JAN-10     Ju Ben
    407614     1253393     Wo, Wo& Luk     Finalizetext     2754111     0     FSC     26-JAN-10     Ju Ben     26-JAN-10     Ju Ben
    but i want output like this
    Edited by: vijayp on Sep 5, 2010 2:05 PM
    Edited by: vijayp on Sep 5, 2010 2:06 PM

    Do you see a version number in what you posted?
    Perhaps DDL for the tables, constraints and indexes?
    Perhaps the DML that inserted a couple of sample rows?
    How about the SQL statement you wrote that is not doing what you want?
    Neither do I so no help is possible at this time.
    We can not look over your shoulder at your monitor. We can not read your mind. We have no idea what you are doing or in what environment you are trying to do it.
    What you have asked is roughly equivalent to ... "My 1996 Mercedes Benz 320SL won't start please tell me why?"
    Perhaps it is out of gas. Perhaps the battery is dead. Perhaps you just didn't turn the key far enough. You get the point.

  • Need help on select statement in ABAP

    Hi,
    I have 2 table. in that I need to do join. But 2 fields of table A that I need to join with the 2 fields in table B.
    But problem is that both the fields of table A can be NULL(either of them).
    i.c.
                          Table A                                                                      Table B
    KONDA     KUNNR      PRICESHEET                                     KONDA       KUNNR
    KA             NULL           A                                                       KA            1000
    KA             NULL           B                                                       KA            1001
    DZ             NULL            C                                                      DZ             1002
    NULL         1000            D                                                       DZ             1003
    NULL         1001            E                                                       DZ             1004
    NULL         1002            F
    NULL         1003            F
    NULL         1004            G
    After Joining I need for KONDA = 'KA'
    KONDA     KUNNR      PRICESHEET 
    KA             NULL           A            
    KA             NULL           B
    NULL         1000            D 
    NULL         1001            E 
    Could you plz help me...Plz reply soon. Thanks in advance
    Regards
    Anutosh

    select a~konda a~kunnr a~pricesheet  from table_a as a
    join table_b as b on ( a~konda = b~konda or a~konda eq space ) and (a~kunnr = b~kunnr or a~kunnr eq space )
    where b~konda = 'KA'.
    Try that
    Edited by: Ramiro Escamilla on Apr 3, 2008 11:48 PM

  • Help in select statement

    CREATE TABLE test
    entrynum NUMBER (19),
    datefield TIMESTAMP (3),
    type NUMBER (2),
    invno varchar2(100),
    entrytype number,
    amount NUMBER (30, 4),
    appliedentryno VARCHAR2 (4000 BYTE)
    Insert into test
    (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
    Values
    (1111, 41, 2, 'aaaa', 2,
    TO_DATE('8/18/2005'), 0);
    Insert into test
    (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
    Values
    (1111, -405.3, 1, 'bbbb', 2,
    TO_DATE('8/18/2005'), 2222);
    Insert into test
    (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
    Values
    (1111, 364.3, 6, 'cccc', 2,
    TO_DATE('8/23/2005'), 3333);
    Insert into test
    (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
    Values
    (2222, -405.3, 1, 'bbbb', 1,
    TO_DATE('8/18/2005)', 0);
    Insert into test
    (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
    Values
    (2222, 405.3, 1, 'bbbb', 2,
    TO_DATE('8/18/2005)', 2222);
    Insert into test
    (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
    Values
    (3333, 364.3, 6, 'cccc', 1,
    TO_DATE('8/23/2005)',  0);
    Insert into test
    (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
    Values
    (3333, -364.3, 6, 'cccc', 2,
    TO_DATE('8/23/2005)',3333);
    COMMIT;
    case 1 when datefield<= '8/18/2005'
    then my output should be
    entrynum     amount            type        datefield             amountdue          unappliedamount
    1111            41                   2           8/18/2005              -364.3                   0
    1111          -405.3               1           8/18/2005              -364.3                   0
    case 3 when datefield<= '8/23/2005'
    then my output should be
    entrynum     amount            type        datefield             amountdue          unappliedamount
    11111            41                  2           8/18/2005             0                             0
    1111            -405.3              1           8/18/2005             0                             0
    1111            364.3               6           8/23/2005             0                             0

    Hello
    Please test your script - it doesn't work.
    XXX> CREATE TABLE test
      2  (
      3  entrynum NUMBER (19),
      4  datefield TIMESTAMP (3),
      5  type NUMBER (2),
      6  invno varchar2(100),
      7  entrytype number,
      8  amount NUMBER (30, 4),
      9  appliedentryno VARCHAR2 (4000 BYTE)
    10  );
    Table created.
    Elapsed: 00:00:00.07
    XXX>
    XXX> Insert into test
      2  (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
      3  Values
      4  (1111, 41, 2, 'aaaa', 2,
      5  TO_DATE('8/18/2005'), 0, '0');
    Insert into test
    ERROR at line 1:
    ORA-00913: too many values
    Elapsed: 00:00:00.01
    XXX> Insert into test
      2  (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
      3  Values
      4  (1111, -405.3, 1, 'bbbb', 2,
      5  TO_DATE('8/18/2005'), 0, '2222');
    Insert into test
    ERROR at line 1:
    ORA-00913: too many values
    Elapsed: 00:00:00.01
    XXX> Insert into test
      2  (entrynum, amount, type, invno, entrytype, datefield, appliedentryno)
      3  Values
      4  (1111, 364.3, 6, 'cccc', 2,
      5  TO_DATE('8/23/2005'), 0, '3333');
    Insert into test
    ERROR at line 1:
    ORA-00913: too many valuesAlso, please put your {noformat}{noformat} before and after your insert statements and the results you are looking for.  Finally, your explanation is missing the date for case 1 and you don't seem to have a case 2.
    HTH
    David
    Edited by: Bravid on Nov 18, 2011 4:58 PM
    Messed up my own code tags!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help with SELECT - selecting range of numbers

    Hi,
    I need a help with SELECT statement. I want to select Dates starting from today and ending 30 days back. So the result would be like:
    TRUNC(SYSDATE)
    TRUNC(SYSDATE) - 1
    TRUNC(SYSDATE) - 2
    TRUNC(SYSDATE) - 3
    TRUNC(SYSDATE) - 30I was thinking to simply select truncated SYSDATE in first column, and in second column numbers 0, 1, 2, ... 30. Then I would simply do a difference first column - second column. But how to select such sequence of numbers? I don't want to select each number (date) in separate select statement and then unioning them.
    Does anybody have an idea?
    Thanks for help, Dan

    SQL> select trunc(sysdate) - level + 1 as dt
      2  from dual
      3  connect by level <= 31
      4  ;
    DT
    07/01/2013
    06/01/2013
    05/01/2013
    04/01/2013
    03/01/2013
    02/01/2013
    01/01/2013
    31/12/2012
    30/12/2012
    29/12/2012
    28/12/2012
    27/12/2012
    26/12/2012
    25/12/2012
    24/12/2012
    23/12/2012
    22/12/2012
    21/12/2012
    20/12/2012
    19/12/2012
    DT
    18/12/2012
    17/12/2012
    16/12/2012
    15/12/2012
    14/12/2012
    13/12/2012
    12/12/2012
    11/12/2012
    10/12/2012
    09/12/2012
    08/12/2012
    31 rows selected

  • SELECT statement in FROM clause - syntax help

    Hi,
    I want to have a SELECT statement in the FROM clause. I get syntax error when doing this and since I am new to ABAP I need som help.
    I want to do the following, (and if anyone has any SELECT statement from their own system which you know there is no syntax error in please post it here so I can analyze the syntax):
    *I leave the INTO itab clause out, since I only want to demonstrate the functionality
    I am trying to get.
    <b>SELECT</b> tableOne~someField
    <b>FROM</b> tab <b>AS</b> tableOne (<b>SELECT</b> someField
                                         <b>FROM</b> tab
                                         <b>WHERE</b> someFiled > 1) <b>AS</b> tableTwo
    <b>WHERE</b> tableOnesomeField > tableTwosomeField
    like I said, the problem is that the select statement in the parenthesis in the from clause seems to be incorrect because I get "wrong expression" when trying to compile. Is this because I cannot have a select statement in the from clause or is it because of a minor syntax error, such as I forgot a dot, or some other sign?
    thanks and regards
    Baran

    sorry i am not enough familiar with sub queries but some error i can see which i will state here.
    1> you have to use sub queries i.e. select in ( ) after where clause because here you are fulfilling a where clause by another select statement.
    like this
    SELECT * FROM SFLIGHT
        INTO WA
        WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).
    2> you cannot specify field name without into clause either you have to use
    select *  or select f1 into tab-f1  like this...
    but if you are using select * without into you have to define
    tables : dbtab.
    selec * from dbtab. like that.
    regards
    shiba dutta

  • MySQL Select Statement Help Required

    I am trying to generate a report in VS 2008 (C#) using a mysql select statement but cannot get it right.
    I have groups that meet on a weekly basis on different days. I want to generate a report that shows me all the members that have not attended their group where they have missed 3 meetings in a row.
    Below is the select statement I have tried but it does not give me the results I am looking for. I have tried to look at all the meetings in a 4 week period but would prefer to look at the last 3 meetings that are recorded. Some groups might not record a meeting every week. So I want to look at the last 3 recorded meetings and count each members attendance and only report on the members with more than 3 meetings missed.
    SELECT COUNT(`groupattendance`.`Attended`) AS Attendance, `smallgroupform`.`MeetingDate`, `userinfo`.`FirstName`, `userinfo`.`Surname`, `smallgroup`.`GroupName`, `groupattendance`.`Attended`, `groupattendance`.`UserID`, `groupattendance`.`GroupID`
    FROM ((`anatomy`.`groupattendance` `groupattendance`
    INNER JOIN `anatomy`.`smallgroupform` `smallgroupform` ON `groupattendance`.`FormID` = `smallgroupform`.`FormID`)
    INNER JOIN `anatomy`.`userinfo` `userinfo` ON `groupattendance`.`UserID` = `userinfo`.`UserID`)
    INNER JOIN `anatomy`.`smallgroup` `smallgroup` ON `groupattendance`.`GroupID` = `smallgroup`.`GroupID`
    WHERE (`smallgroupform`.`MeetingDate` >= DATE_SUB(CURDATE(),INTERVAL 4 WEEK) AND `smallgroupform`.`MeetingDate` <= CURDATE()) AND `groupattendance`.`Attended` = 'False'
    GROUP BY `userinfo`.`UserID`
    HAVING Attendance >= 3
    Thanks,
    Garth.

    Hi Garth,
    Seems no one can help you directly. Try googling your SQL request. Someone may be able to help you. At this point its not really a Cr problem.
    One option is to get all the data and add filtering using the record selection formula.
    Thank you
    Don

Maybe you are looking for

  • Index Vs table partition

    I have table whose growth is 1 million per month and may increase in future. I currently place an index on column which is frequently uses in where clause. there is another column which contains months so it may possible that I make 12 partitions of

  • Photoshop CS3 wont open any files?

    I'm running photoshop cs3 and recently every time I try and open a file nothing happens, well what happens is I see the open file box pop up and disappear and then I can not do anything in PS, every time I click something I hear a noise and thats it,

  • Significant Pixelation in SD DVD from HD source

    I just completed a project in FCP where I edited source from 3 different HD cameras. I imported the source in Apple ProRes, and then downconverted to SD using Compressor. The resulting DVD quality is absolutely terrible - much worse than if I had sim

  • Flashes White Screen After Opening Link in Tabs from RSS  Feed

    Hi. This is a weird glitch/bug that I'm trying to get to the bottom of. It happens very often, that when I open all of my feeds (they are all collected in one folder so I can view them at once) and choose to open a link from one of the feeds in a sep

  • Can't Connect To APS on Essbase(9.3) Console

    HI all, I am not able to connect to aps in essabse console it's showing the error:"Cannot authenticate user. Invalid arguments passed in. Please check the arguments". I am able to run all Essbase java program after starting the aps services.Even i am