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.

Similar Messages

  • Need help with update statement with multiple joins

    I've got the following select statement that is pulling 29 records:
    SELECT
    PPA.PROJECT_ID,
    PPA.SEGMENT1,
    peia.expenditure_item_id,
    peia.expenditure_type,
    pec.expenditure_comment
    FROM PA.PA_PROJECTS_ALL PPA,
    pa.pa_expenditure_items_all peia,
    pa.pa_expenditure_comments pec
    where PPA.segment1 < '2008' and
    PPA.project_id = 52 and -- just run for project # 20077119 for testing
    peia.expenditure_type = 'PAYROLL' and
    peia.project_id = ppa.project_id and
    PEC.EXPENDITURE_ITEM_ID = PEIA.EXPENDITURE_ITEM_ID;
    I need to update the pec.expenditure_comments to a static field for those 29 records. I assume I should start with the following, but not sure how to complete the where:
    update
    pa.pa_expenditure_comments pec
    set pec.expenditure_comment = 'REFERENCE HD#728'
    where
    First time that we've ever needed to update, so any and all help appreciated.

    Try using exists:
    update pa.pa_expenditure_comments pec
    set    pec.expenditure_comment = 'REFERENCE HD#728'
    where exists ( select null
                   from   pa.pa_projects_all ppa
                   ,      pa.pa_expenditure_items_all peia
                   ,      pa.pa_expenditure_comments pec2
                   where  ppa.segment1 < ''    -- not sure what you posted here, so for next time:
                                               -- please put your examples between the code tags.
                   and    ppa.project_id = 52  -- just run for project # 20077119 for testing
                   and    peia.expenditure_type = 'PAYROLL'
                   and    peia.project_id = ppa.project_id
                   and    pec2.expenditure_item_id = peia.expenditure_item_id
                   and    pec2.expenditure_item_id = pec.expenditure_item_id
                 );

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

    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 that month range with flexible first date

    Hello everyone,
    I am trying to create a selection of month range (will be in a WITH clause) for a report to display monthly data. But the first month start date can be any date. (Not necessarily the first date of the month)
    Examples:
    Report input parameters:
    Start Date: 08/10/12
    End Month: Dec 2012
    I was trying to build a with select that will list
    Month_Start, Month_End
    08/10/12, 31/10/12
    01/11/12, 30/11/12
    01/12/12, 31/12/12
    OR
    Month_Start, Next_Month
    08/10/12, 01/11/12
    01/11/12, 01/12/12
    01/12/12, 01/01/13
    End month is optional, so if no value the select will list only
    08/10/12, 01/11/12
    Oracle Database Details is
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    My code so far is
    VARIABLE  P50_START_DATE  VARCHAR2 (10)
    VARIABLE  P50_END_MONTH    VARCHAR2 (10)
    EXEC  :P50_START_DATE  := '10/10/2012';
    EXEC  :P50_END_MONTH   := '31/12/2012';
      SELECT  to_char(:P50_START_DATE) AS start_date
            ,  ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), 1) AS next_month
      FROM dual
      union
       SELECT to_char(ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), ROWNUM-1)) AS start_date
       ,      ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), ROWNUM) AS next_month
       --, rownum
       from all_objects
       where
       rownum <= months_between(to_date(NVL(:P50_END_MONTH, :P50_START_DATE),'DD/MM/YYYY'), add_months(to_date(:P50_START_DATE,'DD/MM/YYYY'), -1))
       and rownum > 1If I put comment – on line and rownum > 1, as
    -- and rownum > 1The result I get is
    START_DATE                     NEXT_MONTH               
    01/10/12                       01/10/12                 
    01/11/12                       01/11/12                 
    01/12/12                       01/01/13                 
    10/10/2012                     01/11/12    But when I try to remove the duplicate period (of the first month) out by restrict rownum, it do not return any rows for the second select at all. The result I get is:
    START_DATE                     NEXT_MONTH               
    10/10/2012                     01/11/12    Can anyone advise what wrong with the select statement ?
    Thanks a lot in advance,
    Ann

    Hi,
    Here's one way:
    WITH   params      AS
         SELECT     TO_DATE (:p50_start_date, 'DD/MM/YYYY')     AS start_date
         ,     TO_DATE (:p50_end_month,  'DD/MM/YYYY')     AS end_date
         FROM     dual
    SELECT     GREATEST ( start_date
               , ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                            , LEVEL - 1
              )               AS month_start
    ,     LEAST     ( end_date
              , ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                          , LEVEL
                        ) - 1
              )               AS month_end
    FROM    params
    CONNECT BY     LEVEL     <= 1 + MONTHS_BETWEEN ( end_date
                                      , TRUNC (start_date, 'MONTH')
    ;:p50_end_month doesn't have to be the last day of the month; any day will work.
    If you want to generate a Counter Table containing the integers 1 througn x in SQL, you could say
    SELECT  ROWNUM  AS n
    FROM    all_objects
    WHERE   ROWNUM  <= x
    ;but, starting in Oracle 9.1, it's much faster to say
    SELECT  LEVEL   AS n
    FROM    dual    -- or any table containing exactly 1 row
    CONNECT BY  LEVEL <= x
    ;Also, x can be greater than the number of rows in all_objects.

  • Need help with select stmnt but not loosing unique index scan...

    it's 10 g
    any way to get this faster using uniqe index?
    select * from my_test3
    where c1 = :a_value
    and c3 = maximum value by c1....
    Any work arround so that i do not loose my unique index scan..
    i know I can use subquery or some..but that is not a good solution...
    SQL> drop table my_test3;
    Table dropped.
    SQL>
    SQL> create table my_test3
      2  (c1 number ,
      3   c3 timestamp );
    Table created.
    SQL> alter table my_test3
      2   add primary key(c1,c3);
    Table altered.
    SQL>
    SQL> insert into my_test3  values(1,systimestamp);
    1 row created.
    SQL> insert into my_test3  values(1,systimestamp);
    1 row created.
    SQL> insert into my_test3  values(1,systimestamp);
    1 row created.
    SQL> insert into my_test3  values(1,systimestamp);
    1 row created.
    SQL> insert into my_test3  values(2,systimestamp);
    1 row created.
    SQL> insert into my_test3  values(3,systimestamp);
    1 row created.
    SQL> insert into my_test3  values(3,systimestamp);
    1 row created.
    SQL> insert into my_test3  values(5,systimestamp);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL>
    SQL> set line 130
    SQL> set long 400000
    SQL> explain plan for
      2  select * from my_test3
      3  where c1 = :val2
      4  and c3 = :val4;
    Explained.
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 964817202
    | Id  | Operation         | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |              |     1 |    26 |     1   (0)| 00:00:01 |
    |*  1 |  INDEX UNIQUE SCAN| SYS_C0047363 |     1 |    26 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - access("C1"=TO_NUMBER(:VAL2) AND "C3"=TO_TIMESTAMP(:VAL4))
    13 rows selected.
    SQL>

    select my.c2 as c1, my.c3 as c3 from (select t3.c1 c2, t3.c3, max(t3.c3) over (partition by t3.c1 ) as cme from my_test3 t3) my
    where my.c3 = cme
    C1 C3
    1 07-MAY-08 01.26.26.617994 PM
    2 07-MAY-08 01.26.26.621817 PM
    3 07-MAY-08 01.26.26.628041 PM
    5 07-MAY-08 01.26.26.631821 PM
    | Id  | Operation         | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |              |     8 |   312 |     2   (0)| 00:00:01 |
    |*  1 |  VIEW             |              |     8 |   312 |     2   (0)| 00:00:01 |
    |   2 |   WINDOW BUFFER   |              |     8 |   208 |     2   (0)| 00:00:01 |
    |   3 |    INDEX FULL SCAN| SYS_C0025048 |     8 |   208 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("MY"."C3"="CME")
    Note
       - dynamic sampling used for this statementYou'll need to see if you lose the index or not...

  • Need help with Object States or Buttons?

    I currently work in InDesign to compile layouts and present design decks to clients. Our template includes an approval section (Not Approved, Revised, Approved) that we currently have as white/black bubbles that we change manually on each page. I've been trying to find a way to speed up this process. I know that in InDesign you can create buttons than you can then click on-off on your PDF - we used to do this but it is too time consuming (we have PDF's anywhere from 25-120 pages). I have been playing around with Object States, so we can quickly update the bubbles in InDesign itself as we work.
    Does anyone know of a way to change the state of multiple objects on multiple pages at the same time? (For example, if I want to change all pages to "Approved" at the same time - or if I only wanted to do some, but not all, of the pages.)
    Can anyone recommend any other InDesign tools that may be able to create a similar function for an "approval" stamp, but that still is done in InDesign (not in the PDF after exporting)?

    I was hoping that wouldn't be the only way. My have multiple master pages already, and not all pages will be "approved" at the same time. So we've run into issues with putting these on the masters as it gets easier to miss them.

  • Need Help with Creating the SQl query

    Hi,
    SQL query gurus...
    INFORMATION:
    I have two table, CURRENT and PREVIOUS.(Table Defs below).
    CURRENT:
    Column1 - CURR_PARENT
    Column2 - CURR_CHILD
    Column3 - CURR_CHILD_ATTRIBUTE 1
    Column4 - CURR_CHILD_ATTRIBUTE 2
    Column5 - CURR_CHILD_ATTRIBUTE 3
    PREVIOUS:
    Column1 - PREV_PARENT
    Column2 - PREV_CHILD
    Column3 - PREV_CHILD_ATTRIBUTE 1
    Column4 - PREV_CHILD_ATTRIBUTE 2
    Column5 - PREV_CHILD_ATTRIBUTE 3
    PROBLEM STATEMENT
    Here the columns 3 to 5 are the attributes of the Child. Lets assume that I have two loads, One Today which goes to the CURRENT table and one yesterday which goes to the PREVIOUS table. Between these two loads there is a CHANGE in the value for Columns either 3/4/5 or all of them(doesnt matter if one or all).
    I want to determine what properties for the child have changed with the help of a MOST efficient SQL query.(PARENT+CHILD is unique key). The Database is ofcourse ORACLE.
    Please help.
    Regards,
    Parag

    Hi,
    The last message was not posted by the same user_name that started the thread.
    Please don't do that: it's confusing.
    Earlier replies give you the information you want, with one row of output (maximum) per row in current_tbl. There may be 1, 2 or 3 changes on a row.
    You just have to unpivot that data to get one row for every change, like this:
    WITH     single_row  AS
         SELECT     c.curr_parent
         ,     c.curr_child
         ,     c.curr_child_attribute1
         ,     c.curr_child_attribute2
         ,     c.curr_child_attribute3
         ,     DECODE (c.curr_child_attribute1, p.prev_child_attribute1, 0, 1) AS diff1
         ,     DECODE (c.curr_child_attribute2, p.prev_child_attribute2, 0, 2) AS diff2
         ,     DECODE (c.curr_child_attribute3, p.prev_child_attribute3, 0, 3) AS diff3
         FROM     current_tbl    c
         JOIN     previous_tbl   p     ON  c.curr_parent     = p.prev_parent
                                AND c.curr_child     = p.prev_child
         WHERE     c.curr_child_attribute1     != p.prev_child_attribute1
         OR     c.curr_child_attribute2     != p.prev_child_attribute2
         OR     c.curr_child_attribute3     != p.prev_child_attribute3
    ,     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL <= 3
    SELECT     s.curr_parent     AS parent
    ,     s.curr_child     AS child
    ,     CASE     c.n
              WHEN  1  THEN  s.curr_child_attribute1
              WHEN  2  THEN  s.curr_child_attribute2
              WHEN  3  THEN  s.curr_child_attribute3
         END          AS attribute
    ,     c.n          AS attribute_value
    FROM     single_row     s
    JOIN     cntr          c     ON     c.n IN ( s.diff1
                                    , s.diff2
                                    , s.diff3
    ORDER BY  attribute_value
    ,            parent
    ,            child
    ;

  • Need help with division within a query

    Hello all~
    I am trying to divide these two columns to get a % of case numbers involving an accident. Im pretty sure you need to use decode to avoid the divide by 0 error but not sure how to implement this within my query. When i run this query below, it gives me the result of "1", which is not correct. Can someone help me please?
    Oracle Version 10g
    ACCIDENT is a datatype VARCHAR
    CASE_NUMBER is a datatype VARCHAR
    select to_char(count(ACCIDENT),'999,999,999') as "ACCIDENT",
    to_char(COUNT(CASE_NUMBER),'999,999,999')as "CASE NUMBER",
    round(ratio_to_report(count(accident))
    OVER()*100,2)as "%"
    from      "PURSUIT"
    WHERE ACCIDENT = 'Y'
    AND
    (:P1_BEG_DATE IS NULL AND :P1_END_DATE IS NULL
    OR
    pursuit_date BETWEEN to_date(:p1_beg_date,'MM/DD/YYYY') and to_date
    (:p1_end_date,'MM/DD/YYYY'))
    AND(:P1_TROOP=pursuit.officer_troop OR :p1_troop IS NULL) 
    AND(:P1_RADIO=pursuit.officer_radio OR :p1_radio IS NULL)
    group by case_numberThanks
    Deanna

    Are you sure that the ANDs and ORs in your WHERE clause will take precedence properly?
    Also, if you always select only cases where there has been an accident, what percentage would you like to display? Surely in this case the percentage of cases involving in accident in cases where there was an accident.. is 100%?
    as a simpler example
    SELECT
      accident,
      ROUND(RATIO_TO_REPORT(count(*)) OVER() * 100)
    FROM
      pursuit
    GROUP BY
      accidentHere's a trick to neaten up those IS NULLs:
    SELECT
      accident,
      ROUND(RATIO_TO_REPORT(count(*)) OVER() * 100)
    FROM
      pursuit
    WHERE
      pursuit_date >= COALESCE(:p1_beg_date, pursuit_date) AND
      pursuit_date <= COALESCE(:p1_end_date, pursuit_date) AND
      officer_troop LIKE :p1_troop AND
      offcier_radio LIKE :p1_radio
    GROUP BY
      accidentTo wildcard a date, simply pass NULL in; the coalesce will replace the null with the pursuit_date from the record (thus the >= and <= becomes true)
    To wildcard the troop or the radio, simply pass a '%' symbol as the value of the parameter. If the front end code is already set up to pass nulls, use the COALESCE trick above

  • Need help with select within select - daterange

    I use Crystal Reports v12.3.0.601 - I am a beginner.
    Problem:
    TABLE: ACCOUNTBILLFEE
    Columns are   
    FOLDERRSN
    STAMPDATE
    BILLNUMBER
    PAYMENTAMOUNT
    There are over 500,000 rows/ records...
    And I need to report the FOLDERRSN which has at least one {ACCOUNTBILLFEE.STAMPDATE} in DateTime
    (2014, 05, 01, 00, 00, 01) to DateTime (2014, 05, 31, 23, 59, 59)
    Out-put required is:
    FOLDERSN | STAMPDATE | BILLNUMBER   | PAYMENTAMOUNT
    Group by FOLDERRSN
    1010234               May01,2014                 1111                      25000
                                  May25, 2014                1112                       5000
                                  Jan 05, 2013                  998                          500
    1034567                May5, 2014                11325                       5000
    1033999                May15, 2014               6752                       15000
                                  Dec5 , 2011                1132                       25000
    Please help -
    The critical part for me, is to display  payments not within the date range in 'select expert' statement.
    Currenlty my report reflects only payments for FOLDERRSN, where {ACCOUNTBILLFEE.STAMPDATE} in DateTime
    (2014, 05, 01, 00, 00, 01) to DateTime (2014, 05, 31, 23, 59, 59) and not other payments outside the date range specified.
    Thank you for your time.

    Hi Abilash,
    This worked !!!
    My brother helped me with it here....ofcourse you have intiated the intial idea.
    It worked when i used the following SQL at 'Add Command'
    Select * from DATABASE_NAME.ACCOUNTBILLFEE A
    Where A.FOLDERSN = any ( select B.FOLDERSN from DATABASE_NAME.ACCOUNTBILLFEE B
    where B.STAMPDATE >= TO_DATE('20140501', 'YYYYMMDD')
    AND  B.STAMPDATE <= TO_DATE('20140531', 'YYYYMMDD'))
    Excellent support - Thank you so much for your immediate attention and response.
    I know, how hard it is to understand someones requirement and suggest solutions.
    You are the best and most helpful I have ever come across in my life.
    Thank you for your kind heart and extending help to me.
    Regs,
    Sridhar Lam

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

  • Need help with If statement Please

    Hi guys,
    This is my first time posting and sorry if for some reason i post incorrectly.
    I am having trouble figuring out what I am doing with my if Statement and why the compiler is giving me an error which says 'cannot find symbol';
    Just incase you need to see the code here it is. And please any pointers would help me get back on track. And please dont laugh at the novice code i just started^^;
    import java.util.*;
    import java.text.*;
    public class Student
         public static void main(String[]args)
         Scanner scan=new Scanner(System.in);
         double std1, std2, std3, num1, num2, num3, num4;
         String a, answer1, name1;
    System.out.println("Welcome to _____ program, press any button to continue: ")
    a=scan.nextLine();
    System.out.println("Good, would you like to enter a grade for a student(y/n)?");
    answer1=scan.nextLine();
    if (answer1 == y)
         System.out.println("Please enter the students name ");
                             name1=scan.nextLine();
                             System.out.println("Please label the test number ");
                             num1=scan.nextDouble();
                             System.out.println("Please enter the grade, "+name1+" recieved");
    std1=scan.nextDouble();
    if (answer1==n)
         System.out.println("Thank you for trying my program ");
    else
    System.out.println("It's obvious you couldn't follow a simple direction good bye ");

    Thanks Flounder,
    I'll keep in mind to edit the code the way you told me too.
    As far as the code goes, what do you mean 'y' is not a string and should be a variable. All I'm trying to do is give a true false statement.
    For example
    if (input==y)
    System.out.println("________");
    And in my code it gives an error stating that y is a variable.
    I dont understand why.
    Thanks much for all your replies.

  • [8i] Need help with hierarchical (connect by) query

    First, I'm working in 8i.
    My problem is, I keep getting the error ORA-01437: cannot have join with CONNECT BY.
    And, the reason I get that error is because one of the criteria I need to use to prune some branches with is in another table... Is there anyway to work around this? I tried an in-line view (but got the same error). I thought about using the connect by query as an in-line view and filtering off what I don't want that way, but I'm not sure how to filter out an entire branch...
    Here is some simplified sample data:
    CREATE TABLE     bom_test
    (     parent          CHAR(25)
    ,     component     CHAR(25)
    ,     qty_per          NUMBER(9,5)
    INSERT INTO     bom_test
    VALUES     ('ABC-1','101-34',10);
    INSERT INTO     bom_test
    VALUES     ('ABC-1','A-109-347',2);
    INSERT INTO     bom_test
    VALUES     ('ABC-1','ABC-100G',1);
    INSERT INTO     bom_test
    VALUES     ('ABC-1','1A247G01',2);
    INSERT INTO     bom_test
    VALUES     ('ABC-100G','70052',18);
    INSERT INTO     bom_test
    VALUES     ('ABC-100G','M9532-278',5);
    INSERT INTO     bom_test
    VALUES     ('1A247G01','X525-101',2);
    INSERT INTO     bom_test
    VALUES     ('1A247G01','1062-324',2);
    INSERT INTO     bom_test
    VALUES     ('X525-101','R245-9010',2);
    CREATE TABLE     part_test
    (     part_nbr     CHAR(25)
    ,     part_type     CHAR(1)
    INSERT INTO     part_test
    VALUES     ('ABC-1','M');
    INSERT INTO     part_test
    VALUES     ('101-34','P');
    INSERT INTO     part_test
    VALUES     ('A-109-347','P');
    INSERT INTO     part_test
    VALUES     ('ABC-100G','M');
    INSERT INTO     part_test
    VALUES     ('1A247G01','P');
    INSERT INTO     part_test
    VALUES     ('70052','P');
    INSERT INTO     part_test
    VALUES     ('M9532-278','P');
    INSERT INTO     part_test
    VALUES     ('X525-101','M');
    INSERT INTO     part_test
    VALUES     ('1062-324','P');
    INSERT INTO     part_test
    VALUES     ('R245-9010','P');This is the basic query (with no pruning of branches):
    SELECT     LEVEL
    ,     b.component
    ,     b.parent
    ,     b.qty_per
    FROM     bom_test b
    START WITH          b.parent     = 'ABC-1'
    CONNECT BY PRIOR     b.component     = b.parentThe query above gives the results:
          LEVEL COMPONENT                 PARENT                        QTY_PER
          1.000 101-34                    ABC-1                          10.000
          1.000 A-109-347                 ABC-1                           2.000
          1.000 ABC-100G                  ABC-1                           1.000
          2.000 70052                     ABC-100G                       18.000
          2.000 M9532-278                 ABC-100G                        5.000
          1.000 1A247G01                  ABC-1                           2.000
          2.000 X525-101                  1A247G01                        2.000
          3.000 R245-9010                 X525-101                        2.000
          2.000 1062-324                  1A247G01                        2.000
    9 rows selected....but I only want the branches (children, grandchildren, etc.) of part type 'M'.
    e.g.:
          LEVEL COMPONENT                 PARENT                        QTY_PER
          1.000 101-34                    ABC-1                          10.000
          1.000 A-109-347                 ABC-1                           2.000
          1.000 ABC-100G                  ABC-1                           1.000
          2.000 70052                     ABC-100G                       18.000
          2.000 M9532-278                 ABC-100G                        5.000
          1.000 1A247G01                  ABC-1                           2.000Any suggestions?

    Hi,
    user11033437 wrote:
    First, I'm working in 8i.
    My problem is, I keep getting the error ORA-01437: cannot have join with CONNECT BY.
    And, the reason I get that error is because one of the criteria I need to use to prune some branches with is in another table... Is there anyway to work around this? I tried an in-line view (but got the same error). Post your query. It's very hard to tell what you're doing wrong if we don't know what you're doing.
    ...but I only want the branches (children, grandchildren, etc.) of part type 'M'.
    e.g.:
    LEVEL COMPONENT                 PARENT                        QTY_PER
    1.000 101-34                    ABC-1                          10.000
    1.000 A-109-347                 ABC-1                           2.000
    1.000 ABC-100G                  ABC-1                           1.000
    2.000 70052                     ABC-100G                       18.000
    2.000 M9532-278                 ABC-100G                        5.000
    1.000 1A247G01                  ABC-1                           2.000
    You mean you want don't want the descendants (children, grandchildren, etc.) of any component whose part_type is not 'M'.
    The part_type of the component itself doesn't matter: component '101-34' is included, even though its part_type is 'P', and component 'X525-101' is excluded, even though its part_type is 'M'.
    >
    Any suggestions?Sorry, I don't have an Oracle 8.1 database at hand now. All three of the queries below get the correct results in Oracle 10.2, and I don't believe they do anything that isn't allowed in 8.1.
    You can't do a join and CONNECT BY in the same query on Oracle 8.1.
    I believe you can do one first, then the other, using in-line views. The frist two queries do the join first.
    --     Query 1: Join First
    SELECT     LEVEL
    ,     component
    ,     parent
    ,     qty_per
    FROM     (     -- Begin in-line view to join bom_test and part_test
              SELECT     b.component
              ,     b.parent
              ,     b.qty_per
              ,     p.part_type     AS parent_type
              FROM     bom_test     b
              ,     part_test     p
              WHERE     p.part_nbr     = b.parent
         )     -- End in-line view to join bom_test and part_test
    START WITH     parent     = 'ABC-1'
    CONNECT BY     parent          = PRIOR component
         AND     parent_type     = 'M'
    ;Query 2 is very much like Query 1, but it does more filtering in the sub-query, returning only rows hose part_type or whose parent's part_type is 'M". Your desired result set will be a tree taken entirely from this set. Query 2 may be faster, because the sub-query is more selective, but then again, it may be slower because it has to do an extra join.
    {code}
    -- Query 2: Join first, prune in sub-query
    SELECT     LEVEL
    ,     component
    ,     parent
    ,     qty_per
    FROM     (     -- Begin in-line view to join bom_test and part_test
              SELECT     b.component
              ,     b.parent
              ,     b.qty_per
              ,     p.part_type     AS parent_type
              FROM     bom_test     b
              ,     part_test     p
              ,     part_test     c
              WHERE     p.part_nbr     = b.parent
              AND     c.part_nbr     = b.component
              AND     'M'          IN (c.part_type, p.part_type)
         )     -- End in-line view to join bom_test and part_test
    START WITH     parent     = 'ABC-1'
    CONNECT BY     parent          = PRIOR component
         AND     parent_type     = 'M'
    {code}
    Query 3, below, takes a completely different approach. It does the CONNECT BY query first, then does a join to see what the parent's part_type is. We can easily cut out all the nodes whose parent's part_type is not 'M', but that will leave components like 'R245-9010' whose parent has part_type 'M', but should be excluded because its parent is excluded. To get the correct results, we can do another CONNECT BY query, using the same START WITH and CONNECT BY conditions, but this time only looking at the pruhed results of the first CONNECT BY query.
    {code}
    --     Query 3: CONNECT BY, Prune, CONNECT BY again
    SELECT     LEVEL
    ,     component
    ,     parent
    ,     qty_per
    FROM     (     -- Begin in-line view of 'M' parts in hierarchy
              SELECT     h.component
              ,     h.parent
              ,     h.qty_per
              FROM     (     -- Begin in-line view h, hierarchy from bom_test
                        SELECT     component
                        ,     parent
                        ,     qty_per
                        FROM     bom_test
                        START WITH     parent     = 'ABC-1'
                        CONNECT BY     parent     = PRIOR component
                   ) h     -- End in-line view h, hierarchy from bom_test
              ,     part_test     p
              WHERE     p.part_nbr     = h.parent
              AND     p.part_type     = 'M'
         )     -- End in-line view of 'M' parts in hierarchy
    START WITH     parent     = 'ABC-1'
    CONNECT BY     parent     = PRIOR component
    {code}
    I suspect that Query 3 will be slower than the others, but if the CONNECT BY query is extremely selective, it may be better.
    It would be interesting to see your findings using the full tables. Please post your observations and the explain plan output.
    As usual, your message is a model of completeness and clarity:
    <ul>
    <li>good sample data,
    <li> posted in a way people can use it,
    <li>clear results,
    <li> good explanation
    <li> nciely formatted code
    </ul>
    Keep up the good work!

Maybe you are looking for