Need Help in SQL Query

Hi all,
I have data in the following manner:
CASE_NUMBER HOURS FLAG
1000 10 0
1000 20 0
1000 30 1
1000 40 0
1000 50 1
Here I need to Calculate the total hours for a Case_number till i see the flag as 1.
Here the result must be 10+20+30 Hrs
Another Example
CASE_NUMBER HOURS FLAG
2000 10 1
2000 20 1
Here the result must be only 10.
I am struggling to write a SQL query for this.
Anyones help will be very much greatful
Thanks in Advance
Regards,
Sengathir Subbarayan

Look up analytical functions.
something like sum(hours) OVER (PARTITION BY case_number ORDER BY something)
will give you the sum for all rows.
Then you probably want to "throw away" those rows after the flag maybe by summing the flag column too, and throw away all those where the flag is greater than 1 and where it is equal to 1 except for the first one.
I suspect you actually have some other column (other than the number of hours) that define your order - that's what you put in the ORDER BY.
Jon

Similar Messages

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Need help qith sql query

    I have a table with Columns as as below
    id number primary key
    object_name varchar2(100)
    object_value varchar2(100)
    Data is stored as follows
    id object_name object_value
    10 prop_num 436
    20 city dallas
    40 Misc 1 90
    50 Misc 1 desc min amount
    60 Misc 2 700
    70 Misc 2 desc interest amount
    80 Misc 3
    80 Misc 3 desc
    SQL should return result as shown below
    id object_name object_value
    10 prop_num 436
    20 city dallas
    40 min amount 90
    50 interest amount 700
    I have done this through plsql code by creating temp table. But I need to do it in a sql query. I am stuck here
    Any pointers/help is appreciated
    Thanks
    Edited by: user9327712 on Mar 11, 2010 8:14 AM

    I have a table where the ids are stored.
    *"object name"* column values are actually another table columns stored as rows here. So in our example prop_num, city,Misc 1, Misc 1 desc, Misc 2, Misc 2
    desc,Misc 3 , Misc 3 desc are all columns. These would not change any time
    The column object_value has values stored for respective columns.
    436, dallas , 90 , min amount , 700 , interest amount are all column values. So these can change.
    id object_name object_value
    10 prop_num 436
    20 city dallas
    40 Misc 1 90
    50 Misc 1 desc min amount
    60 Misc 2 700
    70 Misc 2 desc interest amount
    80 Misc 3
    90 Misc 3 desc
    Edited by: user9327712 on Mar 11, 2010 9:57 AM
    Edited by: user9327712 on Mar 11, 2010 10:00 AM
    Edited by: user9327712 on Mar 11, 2010 10:00 AM

  • Complete novice needs help getting SQL Query into Crystal Reports XI

    Post Author: MissMarnie
    CA Forum: Data Connectivity and SQL
    So I was given an intro level web course and a monster reference guide in prep to format a report. One of our developers wrote me everything I need for the report into a SQL Query and now I'm supposed to format it in CR XII literally do not know what to do from here. I'm able to set up the correct server as a datasource, if that's useful, but I don't know how to make the querey into a bunch of formattable fields in  CR. If anyone can walk me through this, I'd be so grateful. I've attempted to look up SQL query in both the help and the book but I keep hitting a wall. The help dialog says things like "press this button" with no reference to what "this button" is. I'm sure it's obvious to the knowledgeable but I'm in a complete fog. Thanks in advance   

    Post Author: synapsevampire
    CA Forum: Data Connectivity and SQL
    IF you're trying to get assistance with setting up a query as the source for a report, try posting your Crystal version and the database type.
    Different software works differently.
    In CR 9 and above, under the connection to the database you'll see Add Command. Select that and you can paste the query in.
    As for not knowing how to generate a report, that requires experience, there's no generic solution of course..
    -k

  • Need help in SQL Query: Update a row in a table & insert the same row into another table

    I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
    Thanks in Advance.

    Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
    SQL> var v_id number
    update tableA  
    set colB='ABC' 
    where colC='XYZ' 
    returning id into :v_id;
    insert into table A_History (ID, colA, colB, ColC)  
    select id, ColA, ColB, ColC  
    from tableA  
    where id = :v_id;   

  • Need help with SQL Query

    I am trying to build a query that sums up 12 columns depending on some accounting variables.
    example:
    SELECT gbmcu, gbco, gbfy,'',SUM(gban01 gban02 gban03 gban04 gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12) AS Oil_Volumes
    FROM PRODDTA.F0902
    WHERE GBCO = '00099'
    AND GBFY = 5
    AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
    GROUP BY gbmcu, gbco, gbfy
    The condition that changes is :AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
    I need to do this for 17 different conditions - I need to make the query as optimized as possible.
    I tried using a case statement but that takes forever (the table is over 4 million records to scan through).
    Please let me know if anyone has any suggestions on how to create something to perform these calculations.
    thanks,
    Pam

    I think I would tend to write that query as:
    SELECT gbmcu, gbco, gbfy,
           SUM(CASE WHEN gblt = 'QA' AND gbobj = 5015 AND gbsub = '105' THEN
                    gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Sales
           SUM(CASE WHEN gblt = 'QU' AND gbobj = 5015 AND gbsub = '105' THEN
                    gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Volumes
    FROM proddta.f0902
    WHERE gbco = '00099' and
          gbfy = 5 and
          gblt IN ('QA', 'QU') and
          gbpbj = 5015 and
          gbsub = '105'
    GROUP BY gbmcu, gbco, gbfySUM the CASE rather than CASE SUM. Also, as written, your query will look at all of the records in f0902 whether or not they meet one of the Case criteria, so I would put the required values in the WHERE clause as well. Your samples only show gblt changing, so you may need to make the gbpbj and gbsub predicates IN lists as well.
    If the query runs in 1.5 hours calculating one value, I would expect it to be about the same calculating 17 values, since I would bet that most of the run time is accessing the table rather than doing the math. It would almost certainly be faster than running essentially the same query 17 times.
    Indexes on some or all of the columns in the WHERE clause may help, depending on how selective the columns are. At a guess, I would suggest that gbco and gbfy would be good candidates.
    Finally, are you sure that gbsub is a character field? The only example we have is a number.
    HTH
    John

  • Need help with sql query dates

    Hi,
    I have a sql query where i need to extract some info between given dates. The where clause of this query is as follows:
    WHERE CPD_BUS_UNIT=:ESI_PRM_1
    AND CPD_VOUCHER_DATE >= :P_DATE_FROM
    AND CPD_VOUCHER_DATE < (:P_DATE_TO+1)
    When i execute the query in toad, i can view the data but not the execution plan.It gives an error ORA-00932-Inconsistent Datatypes.
    But when i remove (+1) from :P_DATE_TO, i can c the execution plan and data. Will the data be different from the previous one.
    Please suggest how to rewrite the query.

    Can you please give it a try?
    WHERE CPD_BUS_UNIT=:ESI_PRM_1
    AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM)
    AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1) Regards

  • Need help writing sql query

    i am trying to write sql query for a single recordset.
    I have an items table with all the standard item info and an item_colorID.
    i have a color_lookup table with 2 columns, item_colorID and color_ID
    i have a colors table with 2 columns, color_ID and color
    i want to join the tables and filter it so that a repeat region shows dynamic data of item name, description, thumb, price
    and also a list/menu dynamically populated by color
    filtered so that each item shows in the list/menu only the colors that the item has available.
    i have tried different variations of this sql
    SELECT * FROM items INNER JOIN color_lookup ON color_lookup.item_colorID = items.item_colorID INNER JOIN colors ON colors.color_ID = color_lookup.color_ID WHERE items.itemCatID = 3 ORDER BY items.itemName
    but the list/menu shows every color choice multiplied by the number of items in that color
    ie  White will show 80+ times.
    thanks for your help,
    jim balthrop

    bregent,
    thanks for your help.
    I am building a shopping cart and i have a recordset to list the items and a repeat region for that recordset
    i have a second recordset for the colors joined to the item_colorID nested inside the repeat region.
    the shopping cart software has a 'lookup from recordset' choice for the add to cart servior behavior
    and then i bind to the columns on the cart page.
    it produces this code
    if (isset($totalRows_rs_itemscat3) && $totalRows_rs_itemscat3 > 0)    {
        $row_rs_itemscat3 = WAEC_findRecordMySQL($rs_itemscat3, "item_ID", $ATC_itemID);
        if ($row_rs_itemscat3)    {
          $ATC_itemName = "".$row_rs_itemscat3['itemName']  ."";// column binding
          $ATC_itemDescription = "".$row_rs_itemscat3['itemShortDesc']  ."";// column binding
          $ATC_itemWeight = floatval("".$row_rs_itemscat3['itemWeight']  ."");// column binding
          $ATC_itemQuantity = "".$_POST["Farrington_1_Quantity_Add"]  ."";// column binding
          $ATC_itemPrice = floatval("".$row_rs_itemscat3['itemPrice']  ."");// column binding
          $ATC_itemThumbnail = "".$row_rs_itemscat3['itemThumb']  ."";// column binding
          $ATC_itemcolorchoice = "".$row_rs_colors['color']  ."";// column binding
          mysql_data_seek($rs_itemscat3, 0);
          $row_rs_itemscat3 = mysql_fetch_assoc($rs_itemscat3);
    the column binding for the colors is from a different recordset and when redirecting to the cart page the color info will not show.
    So my thinking is if i could get the color list/menu to populate from the same recordset as the item listing, it would solve my add to cart server behavior.
    Is it possible to do this with only one recordset?
    the products page and the cart page can be seen
    http://www.farrington-enterprises.com/rain-gutters.php
    add an item to the cart with any color choice and the color info does not carry to the cart.

  • Need help regarding sql query

    hii All
    I need help for pl/sql function.
    I build a function for monthly attendance all employees.
    but now i want to show all Sundays with 'S' and others respectively 'P' and 'A'.
    Currently Sunday also shows 'A'
    So please help
    SQL queries ... like
    SELECT DISTINCT AL.USERNAME,
    CASE WHEN DAY1 =1 THEN 'P' ELSE 'A' END DAY1,
    CASE WHEN DAY2 =1 THEN 'P' ELSE 'A' END DAY2,
    CASE WHEN DAY3 =1 THEN 'P' ELSE 'A' END DAY3,
    CASE WHEN DAY31 =1 THEN 'P' ELSE 'A' END DAY31
    FROM
    SELECT DISTINCT USERNAME, SUM(CASE WHEN
    fromdt=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY1
    ,SUM(CASE WHEN
    fromdt +1=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY2,
    SUM(CASE WHEN
    fromdt+30=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY31
    FROM ( SELECT DISTINCT TRUNC(LOGIN_DATE)LOGIN_DATE ,USERNAME FROM FCDM_AUDIT_TRAIL_NEW WHERE
    TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
    -- to_date( login_date, 'dd-mom-yyyy') between to_date( fromdt, 'dd-mom-yyyy') and to_date( todt, 'dd-mom-yyyy')
    ) L
    GROUP BY USERNAME
    ) AL;
    how can i show matched Sundays and show with 'SUN' or 'S'
    Regards
    vij..

    Try this way:
    SELECT USERNAME,
           MAX(CASE WHEN to_char(fromdt,'d')='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt,'d')!='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY1,
           MAX(CASE WHEN to_char(fromdt+1,'d')='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt+1,'d')!='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY2,
           MAX(CASE WHEN to_char(fromdt+30,'d')='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt+30,'d')!='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY31
    FROM
    (SELECT DISTINCT TRUNC(LOGIN_DATE) LOGIN_DATE,
            USERNAME
       FROM FCDM_AUDIT_TRAIL_NEW
      WHERE TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
    ) L
    Group by USERNAME
    ;Max
    http://oracleitalia.wordpress.com

  • Need Help on Sql Query

    Hi,
    I have a client requirement to show a report on the device availability. The report should show the output as
    Node Availability%
    Formula for Availability = (Total No. of Failed/Total No. rows) * 100
    My Oracle Table has the following data
    NODE     SUMMARY
    172.16.10.55     Default Interface Ping fail for 172.16.10.55: ICMP timeout
    172.16.10.55     Default Interface Ping restore for 172.16.10.55
    172.16.10.55     Default Chassis Ping restore for 172.16.10.55
    172.16.10.55     Default Chassis Ping fail for 172.16.10.55: ICMP timeout
    172.16.10.55     Default Chassis Ping restore for 172.16.10.55
    172.16.10.55     Default Chassis Ping fail for 172.16.10.55: ICMP timeout
    172.16.10.55     Default Chassis Ping fail for 172.16.10.55: ICMP timeout
    172.16.10.55     Default Interface Ping restore for 172.16.10.55
    172.16.10.55     Default Interface Ping fail for 172.16.10.55: ICMP timeout
    172.16.10.56     Default Chassis Ping restore for 172.16.10.56
    172.16.10.56     Default Interface Ping fail for 172.16.10.56: ICMP timeout
    172.16.10.56     Default Chassis Ping fail for 172.16.10.56: ICMP timeout
    172.16.10.56     Default Chassis Ping restore for 172.16.10.56
    172.16.10.56     Default Chassis Ping fail for 172.16.10.56: ICMP timeout
    172.16.10.56     Default Chassis Ping restore for 172.16.10.56
    172.16.10.56     Default Chassis Ping restore for 172.16.10.56
    172.16.10.56     Default Interface Ping fail for 172.16.10.56: ICMP timeout
    In the above table the Summary column has the details like 'Ping fail' , 'Ping restore' for each Node. So, for each Node I have to compute the Total Ping Fail / (Total Ping Fail + Ping Restore) * 100 to compute the availability %.
    My output should be like the below
    Node Availability%
    172.16.10.55 55.55
    172.16.10.56 54
    Can someone please help me with query.
    I appreciate your help in advance.
    Thanks.
    Regards,
    RaviShankar.

    My Oracle Table has the following dataThat's great, but if you want maximum response to your question, then post CREATE TABLE + INSERT INTO statements.
    I currently do not have the time to turn your data into them.
    And always post the database version you're using.
    http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    Also use the {noformat}{noformat} tag in order to post examples that benefit from staying formatted and thus readable when posted on the forum.
    Simply put the tag before and after your examples.
    For example, when you type:
    {noformat}select *
    from dual;{noformat}
    it will appear as:select *
    from dual;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Need help in SQL query to get only distinct records

    Hi all.
    I am new to oracle SQL and i want to write a query to get only distinct values from 2 tables.
    for example i hade 2 tables table1(employee_id,employee_no,grade) and another table2 with same structure.
    for example data in table1 is
    Employeeid employeeno Grade
    1 101 A
    1 101 B
    1 101 E
    1 101 D
    and data in table 2 is
    Employeeid employeeno Grade
    1 101 A
    1 101 B
    1 101 E
    i want to display only the fourth row like the data that doesnt exist in table2 i,e (1 101 D)
    I had too much records in both tables and i jst want to see the records that is in table 1 not in table 2 only.
    employeeid and employeeno are the same in both tables
    I hope u understand my query. I user left outer join and right outer join bt it displays all the results that and matching and unmatching. I want jst unmatched records.
    Any help is highly Appreciated.
    Thanx in Advance.
    I am using oracle 10G on windows

    Try MINUS:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries004.htm#i2054381
    SQL> -- generating sample data:
    SQL> with t1 as (
      2  select 1 employeeid, 101 employeeno, 'A' grade from dual union
      3  select 1, 101, 'B' from dual union
      4  select 1, 101, 'E' from dual union
      5  select 1, 101, 'D' from dual
      6  )
      7  ,  t2 as (
      8  select 1 employeeid, 101 employeeno, 'A' grade from dual union
      9  select 1, 101, 'B' from dual union
    10  select 1, 101, 'E' from dual
    11  )
    12  --
    13  -- actual query:
    14  --
    15  select employeeid
    16  ,      employeeno
    17  ,      grade
    18  from   t1
    19  minus
    20  select employeeid
    21  ,      employeeno
    22  ,      grade
    23  from   t2;
    EMPLOYEEID EMPLOYEENO G
             1        101 D
    1 row selected.

  • Need help creating SQL Query

    Hi,
    I have this table
    declare @t_date table(cut_off datetime)
    insert into @t_date
    select '20140930'
    union
    select '20140716'
    union
    select '20140715'
    union
    select '20140714'
    union
    select '20140627'
    union
    select '20140625'
    I need this result: Dates nearests to end of month
    In the table on example, I need this output
    2014-09-30
    2014-07-16
    2014-06-27
    Can anyone help me?
    Thanks a lot in advance.
    declare @t_date table(cut_off datetime)
    insert into @t_date
    select '20140930' --this is OK cause eom
    union
    select '20140716' --this is OK cause is the nearest to eom(07)
    union
    select '20140715' --this is KO cause is not the nearest to eom(07)
    union
    select '20140714' --this is KO cause is not the nearest to eom(07)
    union
    select '20140627' --this is OK cause is the nearest to eom(06)
    union
    select '20140625' --this is KO cause is not the nearest to eom(06)

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. You have no keys! Learn how to follow ISO-11179 data element naming conventions and formatting rules.
    Temporal data should use ISO-8601 formats. It is the only –- repeat, only -– format allowed in ANSI/ISO Standard SQL! Code should be in Standard SQL as much as possible and not local dialect. We would use the correct INSERT INTO syntax. 
    Oh, that silly “t_” is called a “tibble” and we laugh at it. 
    CREATE TABLE Foobar_Dates
    (foobar_date DATE NOT NULL PRIMARY KEY);
    INSERT INTO Foobar_Dates
    VALUES
    ('2014-06-25'),
    ('2014-06-27'),
    ('2014-07-14'),
    ('2014-07-15'),
    ('2014-07-16'),
    ('2014-09-30'),
    >> I need this result: for each month I need the date nearest to end of month <<
    Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
    Build good tools and re-use them! 
    The report period table gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Month_Periods
    (month_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (month_name LIKE '[12][0-9][0-9][0-9]-[01][0-9]-00'),
     month_start_date DATE NOT NULL,
     month_end_date DATE NOT NULL,
      CONSTRAINT date_ordering
        CHECK (month_start_date < month_end_date),
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. 
    SELECT M.month_name, MAX(F.foobar_date), 
           OVER (PARTITION BY M.month_name)
      FROM Foobar_Dates AS F, 
           Month_Periods AS M 
     WHERE F.foobar_date BETWEEN M.month_start_date AND M.month_end_date;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Need help with SQL Query (query for certain IDs in a table and then IDs not in result set)

    OK. This is hard to explain but that may be my problem in constructing the query.
    I have a table that has a list of jobs. The jobs information in this table, among other things, is a short description of the job itself (think "title" in phrase form), date, and ID.
    So I can query the table to get all the jobs for a particular grouping of IDs (the only ones I am interested in) that ran successfully for a given time period. But what I want are all the jobs that did not succeed (or therefore are not present in the table) for this group of jobs and for a certain date range. But these are not the only job id's in the table.
    To get the successful ones I do the following:
    SELECT id,short_desc FROM my_table where
                id IN('1230', '1231', '1232', '1239', '1244', '1245',
                '1246', '1247', '1248', '1272', '1280', '1281', '1282',
                '1283', '1284', '1285', '1286', '1249', '1250', '1251',
                '1252', '1253', '1255', '1233', '1234', '1235', '1236',
                '1237', '1238', '1256', '1257','1258', '1254', '1290','1310')
                AND the_date > = SYSDATE - 23/24
                AND to_char(the_date, 'DD-MON-YYYY') = TO_CHAR(CURRENT_DATE, 'DD-MON-YYYY')
    I have tried to use another AND clause with NOT IN and the group or NOT EXISTS but that doesn't work as there are other jobs captured in this table with id's of course. I am only concerned with these id's:
    IN('1230', '1231', '1232', '1239', '1244', '1245',
                '1246', '1247', '1248', '1272', '1280', '1281', '1282',
                '1283', '1284', '1285', '1286', '1249', '1250', '1251',
                '1252', '1253', '1255', '1233', '1234', '1235', '1236',
                '1237', '1238', '1256', '1257','1258', '1254', '1290','1310')
    Someone said to use a temp table. I don't think I have permission and I haven't tried as I want to do this in one query if possible.
    After thinking about this I am at a loss. I tried to do this in the front end but it just became too messy.

    You do not need a physical temp table. You need an in-line view:
    WITH list as (
                  SELECT '1230' id FROM DUAL UNION ALL
                  SELECT '1231' FROM DUAL UNION ALL
                  SELECT '1232' FROM DUAL UNION ALL
                  SELECT '1239' FROM DUAL UNION ALL
                  SELECT '1244' FROM DUAL UNION ALL
                  SELECT '1245' FROM DUAL UNION ALL
                  SELECT '1246' FROM DUAL UNION ALL
                  SELECT '1247' FROM DUAL UNION ALL
                  SELECT '1248' FROM DUAL UNION ALL
                  SELECT '1272' FROM DUAL UNION ALL
                  SELECT '1280' FROM DUAL UNION ALL
                  SELECT '1281' FROM DUAL UNION ALL
                  SELECT '1282' FROM DUAL UNION ALL
                  SELECT '1283' FROM DUAL UNION ALL
                  SELECT '1284' FROM DUAL UNION ALL
                  SELECT '1285' FROM DUAL UNION ALL
                  SELECT '1286' FROM DUAL UNION ALL
                  SELECT '1249' FROM DUAL UNION ALL
                  SELECT '1250' FROM DUAL UNION ALL
                  SELECT '1251' FROM DUAL UNION ALL
                  SELECT '1252' FROM DUAL UNION ALL
                  SELECT '1253' FROM DUAL UNION ALL
                  SELECT '1255' FROM DUAL UNION ALL
                  SELECT '1233' FROM DUAL UNION ALL
                  SELECT '1234' FROM DUAL UNION ALL
                  SELECT '1235' FROM DUAL UNION ALL
                  SELECT '1236' FROM DUAL UNION ALL
                  SELECT '1237' FROM DUAL UNION ALL
                  SELECT '1238' FROM DUAL UNION ALL
                  SELECT '1256' FROM DUAL UNION ALL
                  SELECT '1257' FROM DUAL UNION ALL
                  SELECT '1258' FROM DUAL UNION ALL
                  SELECT '1254' FROM DUAL UNION ALL
                  SELECT '1290' FROM DUAL UNION ALL
                  SELECT '1310' FROM DUAL
    SELECT  l.id,
            nvl(short_desc,'This job failed') short_desc
      FROM      my_table m
      WHERE RIGTH JOIN
                list
              ON (
                      m.id = l.id
                  AND
                      the_date > = SYSDATE - 23/24
                  AND
                      the_date < TRUNC(SYSDATE) + 1
    SY.

  • Need help for SQL Query

    Hi Friends,
    I am using below query to genearet one report.
    {code}
    distinct a.plan_id,
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = a.plan_id)
    "EXT_PAN_REF",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = b.depends_on_ba_plan_id)
    "EXT_PAN_REF1",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = c.drp_plan_id)
    "EXT_PAN_REF2",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = d.srp_plan_id)
    "EXT_PAN_REF3",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = e.DRP_TO_DRP_PLAN_ID)
    "EXT_PAN_REF4",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = f.srp_plan_id)
    "EXT_PAN_REF5"
    FROM BK9_T_BUSINESS_ACTIVITY a,
    BK9_T_BA_DEPENDENCY b,
    BK9_T_BA_DRP_DEP c,
    BK9_T_BA_SRP_DEP d,
    BK9_T_DRP_DEPENDENCY e,
    BK9_T_SYSTEM_DEPENDENCY f
    WHERE     a.plan_id = b.ba_to_ba_plan_id
    AND a.plan_id = c.ba_plan_id
    AND a.plan_id = d.ba_plan_id
    AND c.drp_plan_id = e.DRP_TO_DRP_PLAN_ID
    AND e.DRP_TO_DRP_PLAN_ID = f.drp_plan_id
    {code}
    My output is like this :
    {code}
    22767 19093 19095 19049  19049 19059
    22767 19093 19095 19049  19049 19060
    22767 19093 19095 19062  19062 19060
    22767 19093 19095 19062  19062 19061
    22768 19094 19093 19062  19062 19060
    22768 19094 19093 19062  19062 19061
    {code}
    But What i am looking is like this.
    {code}
    22767 19093 19095 19049  19049 19059
    22767                                               19060
    22767 19093 19095 19062  19062 19060
    22767                                              19061
    22768 19094 19093 19062 19062 19060
    22768                                              19061
    {code}
    Please help.

    Hi,
    Could you please illuminate our minds and spend a bit of time in explaining the logic? That will be much easier without reading the crystal ball which nobody has it here.
    Please read: Re: 2. How do I ask a question on the forums?
    And please provide sample data (create table and insert statement), description of the logic, database version and everything else which is specified in the FAQ
    Regards.
    Al

  • I need help with SQL query

    Hi All,
    I have a problem in the query below. When I run the query I got a pop-up screen to ente value for
    :total_balance,
    :emp_code,
    :from_date,
    :to_date
    total_balance supose to be a result of a calculation.
    Your assistance is apreciated. Thanks,
    Ribhi
    select      FK_VOUCHERSERIAL_N,
         FK_VOUCHERVALUE_DA,
         DESCRIPTION,
         nvl(AMOUNT,0) amount,
         TYPE,
         Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) postive_amount,
         Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) negative_amount,
         Accnt101.total_balanceformula(:total_balance, EMPLOYEE_TRANSACTI.TYPE,Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) ,Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) , nvl(AMOUNT,0)) total_balance
    from      EMPLOYEE_TRANSACTI
    where     FK_EMPLOYEENUMBER0=:emp_code
    and     STATUS=1
    and     FK_VOUCHERVALUE_DA<=:to_date
    and     FK_VOUCHERVALUE_DA>=:from_date
    and     ((TYPE >7 and TYPE <16)
         or (TYPE >34 and TYPE <43)
         or (TYPE =7)
         or (TYPE =18)
         or (TYPE >26 and TYPE <35)
         or (TYPE =17)
         OR (TYPE = 60)
         OR (TYPE = 70)
    OR (TYPE = 72)
    OR (TYPE = 73)
    OR (TYPE = 74)
         or (type = 21)
         or (type =24)
         or (type = 81)
         or (type = 82))
    order by      FK_VOUCHERVALUE_DA asc, FK_VOUCHERSERIAL_N asc, type desc

    Hi Satyaki,
    My problem is with SQL and PL/SQL codd. I managed to convert some of my reports and now I'm facing a problem with converted SQL and PL/SQL code. To give you an Idea the following is a sample of a converted report.
    Pls have a look. (p.s how can i post formated text)
    Thanks,
    Ribhi
    1 - XML template file
    <?xml version="1.0" encoding="UTF-8" ?>
    - <dataTemplate name="Accnt101" defaultPackage="Accnt101" version="1.0">
    - <properties>
    <property name="xml_tag_case" value="upper" />
    </properties>
    - <parameters>
    <parameter name="FROM_DATE" dataType="date" defaultValue="01/01/1998" />
    <parameter name="TO_DATE" dataType="date" defaultValue="31/12/1998" />
    <parameter name="EMP_CODE" dataType="number" defaultValue="44" />
    </parameters>
    <lexicals />
    - <dataQuery>
    - <sqlStatement name="employee_trans">
    - <![CDATA[
    select      FK_VOUCHERSERIAL_N,
         FK_VOUCHERVALUE_DA,
         DESCRIPTION,
         nvl(AMOUNT,0) amount,
         TYPE,
         Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) postive_amount,
         Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) negative_amount,
         Accnt101.total_balanceformula(:total_balance, EMPLOYEE_TRANSACTI.TYPE,Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) ,Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) , nvl(AMOUNT,0)) total_balance
    from      EMPLOYEE_TRANSACTI
    where     FK_EMPLOYEENUMBER0=:emp_code
    and     STATUS=1
    and     FK_VOUCHERVALUE_DA<=:to_date
    and     FK_VOUCHERVALUE_DA>=:from_date
    and     ((TYPE >7 and TYPE <16)
         or (TYPE >34 and TYPE <43)
         or (TYPE =7)
         or (TYPE =18)
         or (TYPE >26 and TYPE <35)
         or (TYPE =17)
         OR (TYPE = 60)
         OR (TYPE = 70)
                    OR (TYPE = 72)
                    OR (TYPE = 73)
                    OR (TYPE = 74)
         or (type = 21)
         or (type =24)
         or (type = 81)
         or (type = 82))
    order by      FK_VOUCHERVALUE_DA asc, FK_VOUCHERSERIAL_N asc, type desc
      ]]>
    </sqlStatement>
    - <sqlStatement name="employee">
    - <![CDATA[
    select NAME,NUMBER0
    from EMPLOYEE
    where  NUMBER0=:emp_code
      ]]>
    </sqlStatement>
    </dataQuery>
    <dataTrigger name="beforeReportTrigger" source="Accnt101.beforereport" />
    - <dataStructure>
    - <group name="G_employee_trans" dataType="varchar2" source="employee_trans">
    <element name="FK_VOUCHERSERIAL_N" dataType="number" value="FK_VOUCHERSERIAL_N" />
    <element name="FK_VOUCHERVALUE_DA" dataType="date" value="FK_VOUCHERVALUE_DA" />
    <element name="DESCRIPTION" dataType="varchar2" value="DESCRIPTION" />
    <element name="AMOUNT" dataType="number" value="AMOUNT" />
    <element name="postive_amount" dataType="number" value="postive_amount" />
    <element name="negative_amount" dataType="number" value="negative_amount" />
    <element name="total_balance" dataType="number" value="total_balance" />
    <element name="TYPE" dataType="number" value="TYPE" />
    <element name="CS_1" function="sum" dataType="number" value="G_employee_trans.total_balance" />
    </group>
    - <group name="G_employee" dataType="varchar2" source="employee">
    <element name="NUMBER0" dataType="number" value="NUMBER0" />
    <element name="NAME" dataType="varchar2" value="NAME" />
    </group>
    <element name="balance" dataType="number" value="Accnt101.balance_p" />
    <element name="CS_2" function="count" dataType="number" value="G_employee.NUMBER0" />
    <element name="CS_3" function="count" dataType="number" value="G_employee_trans.AMOUNT" />
    </dataStructure>
    </dataTemplate>
    2 - PLS/SQL package
    CREATE OR REPLACE PACKAGE Accnt101 AS
         from_date     date;
         to_date     date;
         emp_code     number;
         balance     number := 0 ;
         function postive_amountformula(TYPE in number, amount in number) return number ;
         function negative_amountformula(TYPE in number, amount in number) return number ;
         function BeforeReport return boolean ;
         function total_balanceformula(total_balance in number, TYPE in number, negative_amount in number, postive_amount in number, amount in number) return number ;
         Function balance_p return number;
    END Accnt101;
    3- Package Body
    CREATE OR REPLACE PACKAGE BODY Accnt101 AS
    function postive_amountformula(TYPE in number, amount in number) return number is
    begin
         if ((TYPE>26 and TYPE<35)
              or (TYPE=17))
         then
              return(amount);
         elsif (type = 70)and (amount >=0) then
              return (amount) ;
    elsif (type = 72)and (amount >=0) then
              return (amount) ;
    elsif (type = 73)and (amount >=0) then
              return (amount) ;
    elsif (type = 74)and (amount >=0) then
              return (amount) ;
         elsif (type = 60)and (amount >=0) then
              return (amount) ;
         else
              return (null) ;
         end if;
    RETURN NULL; end;
    function negative_amountformula(TYPE in number, amount in number) return number is
    begin
         if ((TYPE>7 and TYPE<16)
              or (TYPE >34 and TYPE <43)
              or (TYPE=7)
              or (TYPE=18)
              or (type=21)
              or (type=24)
              or (type= 81)
              or (type=82))
         then
              return(amount);
         elsif (type = 70)and (amount <0) then
              return (abs (amount)) ;
    elsif (type = 72)and (amount <0) then
              return (abs (amount)) ;
    elsif (type = 73)and (amount <0) then
              return (abs (amount)) ;
    elsif (type = 74)and (amount <0) then
              return (abs (amount)) ;
         elsif (type = 60)and (amount <0) then
              return (abs(amount)) ;
         else
              return (null) ;
         end if;
    RETURN NULL; end;
    function BeforeReport return boolean is
    var_pos     number(15,3) ;
    var_neg     number(15,3) ;
    beg_bal     number(15,3) ;
    Begin
    begin
    select sum (nvl(amount,0)) into beg_bal
         from EMPLOYEE_TRANSACTI
         where (TYPE=99 or type = 92 or type = 93 or type = 94)
         and to_char(from_date,'YYYY')=to_char(date0,'YYYY')
         and FK_EMPLOYEENUMBER0=emp_code;
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
         beg_bal := 0;
    end;
    begin
         select      sum(nvl(amount,0)) into var_pos
         from      EMPLOYEE_TRANSACTI
         where      
              (TYPE=17
              or type=60
              OR TYPE=70
    oR TYPE=72
    OR TYPE=73
    OR TYPE=74
              or (TYPE>26 and TYPE<35))
         and      fk_vouchervalue_da<from_date
         and      fk_vouchervalue_da>= trunc(from_date,'year')
         and      FK_EMPLOYEENUMBER0=emp_code;
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
         var_pos := 0;
    end;
    Begin     
         select sum(nvl(amount,0)) into var_neg
         from EMPLOYEE_TRANSACTI
         where ((TYPE>7 and TYPE<16)
              or (TYPE >34 and TYPE <43)
              or (TYPE=7)
              or (TYPE=18)
              or (type=21)
              or (type=24)
              or (type= 81)
              or (type=82) )
         and fk_vouchervalue_da<from_date
         and fk_vouchervalue_da>= trunc(from_date,'year')
         and FK_EMPLOYEENUMBER0=emp_code;
         balance :=nvl(beg_bal,0) + nvl(var_pos,0) - nvl(var_neg,0);
         return(true);
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
         balance :=nvl(beg_bal,0) + nvl(var_pos,0) - nvl(var_neg,0);
              RETURN (TRUE);
    end;
    RETURN NULL; end;
    function total_balanceformula(total_balance in number, TYPE in number, negative_amount in number, postive_amount in number, amount in number) return number is
    begin
         if total_balance is null then
         if ((TYPE>7 and TYPE<16)
              or (TYPE >34 and TYPE <43)
              or (TYPE=7)or (TYPE=18)
              or (type=21) or (type=24)
              or (type= 81)
              or (type=82))
         then
              return(balance-negative_amount);
         elsif ((TYPE>26 and TYPE<35) or (TYPE=17))
              then
                   return(balance+postive_amount);
              elsif (type=70 or type=72 or type=73 or type=74
    or type=60) and (amount >=0) then
                   return(balance+postive_amount);
              elsif (type=70 or type=72 or type=73 or type=74
    or type=60) and (amount <0) then
                   return(balance-negative_amount);
         end if;
         else
         if ((TYPE>7 and TYPE<16)
              or (TYPE >34 and TYPE <43)
              or (TYPE=7)or (TYPE=18)
              or (type=21) or (type=24)
              or (type= 81)
              or (type=82))
         then
              return(total_balance-negative_amount);
         elsif ((TYPE>26 and TYPE<35) or (TYPE=17))
              then
                   return(total_balance+postive_amount);
              elsif (type=70 or type=72 or type=73 or type=74
    or type=60) and (amount >=0) then
                   return(total_balance+postive_amount);
              elsif (type=70 or type=72 or type=73 or type=74
    or type=60) and (amount <0) then
                   return(total_balance-negative_amount);
         end if;
         end if ;
    RETURN NULL; end;
    Functions to refer Oracle report placeholders
    Function balance_p return number is
         Begin
         return balance;
         END;
    END Accnt101 ;

Maybe you are looking for

  • Blanket PO functionality in MM

    Hi All: I am a FICO guy and need some assistance in understanding Blanket PO Functionality in SAP. This is what I have understood so far: ? Use FO document type in ME21 ? Use "B" in item category ? Provide a maximum limit for Blanket PO (BPO) ? Provi

  • How to recover a lost audio book purchase?

    I  purchased an audio book last year and I want to download it again to another devise. But I can't find it in my purchases in itunes. If I go to my account and see my transactions I can see there is a record showing I purchased it. What can I do?

  • Much better- and question about constant fan noise

    i couldn't start anew thread a few minutes ago. I replied to 2 threads, then the startanew thread iconmagically appeard! I am not making it up. any way- i posted a while back about noise. I thought it may be the hard drive. But definatley it sounds l

  • Port fowarding not working and Max Payne 3

    I have had a proble with this game badly lagging and some things not being applied to my account while playing etc etc etc Now the ports that I've already opened ( or seemingly not ) are :- UDP 6672 UDP 27900 UDP 27901 443 I have put the Hub 3 ( 3A )

  • All my applications keep quitting unexpectedly.

    It started with firefox and safari. now it's almost anything i'm using. i know my computer is sort of old but is there anything i can do to keep this from happening all the time?