SQL SUM and Group By Function Wrong Result

Hi All,
I have a SQL view with all the payment transaction for a property per month and trying to sum all the transactions per month per property. For some months the total is not correct. For example for property 3856, in Jan 2014, the total should come to
728 but the query lists 2184.
Trans Date
          Amount
Prop Code
31/1/2014
728          
3856   
31/1/2014
-2184         
3856   
31/1/2014
2184         
3856   
Output Required
Year      Month   Amount     Prop Code
2014        1          728              3856
My Query
Select [Prop Code], year(ttp.[Trans Date]) AS [Year], Month(ttp.[Trans Date]) AS [Month], SUM(ttp.[Payment Amount]) as Total
FROM vw_tenant_payments as ttp
GROUP BY [Prop Code], year(ttp.[Trans Date]), Month(ttp.[Trans Date])

Hi All,
I got it, it skipped my mind to restrict the payment type to RENT as even the deposit is in the transaction view
Select
[Prop Code],year(ttp.[Trans
Date])AS[Year],Month(ttp.[Trans
Date])AS[Month],SUM(ttp.[Payment
Amount])asTotal
FROM
vw_tenant_payments
asttp
Where
[Account Code]
='RENT'and[Prop
Code] ='3856'
GROUP
BY[Prop
Code],year(ttp.[Trans
Date]),Month(ttp.[Trans
Date])
Order
by[Prop
Code],[Month]

Similar Messages

  • TableModel with SORT and GROUP BY functions solution.

    Hello all,
    I'd like to represent an EnvelopeTableModel. This class is developed to incapsulate another TableModel and allow user to reorder and group data without changing original values and orders.
    It allows to perform multi column sortings and grouping and
    supports following group functions: EMPTY, COUNT, MIN, MAX, SUM, AVG.
    Here you can download the library, demo version and documentation.
    http://zaval.org/products/swing/
    It would be great to know all your opinions.
    With best regards
    Stanislav Lapitsky

    About 1) and 3).
    These suggestions are almost the same. These features will change GUI component but i want to improve TableModel instead of JTable.
    Using the model user can use JTable for data representation.
    Of course I can improve JTable component and add multiline row/column headers with ability to reorder/group data from component and a lot of another widgets but it isn't my goal.
    About 2) What do you mean "crosstab"?
    Thanks for your 2-cents :-).
    With best regards
    Stas

  • Cannot get wanted data with MAX and GROUP BY function

    Hi
    All
    I have a table like below:
    COLUMN     TYPE
    USER_ID     VARCHAR2 (10 Byte)
    PROCESS_ID     VARCHAR2 (30 Byte)
    END_TIME     DATE(STAMP)
    TO_LOC     VARCHAR2 (12 Byte)
    TO_LOC_TYPE     VARCHAR2 (15 Byte)
    FROM_LOC      VARCHAR2 (12 Byte)
    ITEM_ID     VARCHAR2 (25 Byte)
    CASES     NUMBER (12,4)
    LMS_UDA1      VARCHAR2 (250 Byte)
    ZONE     VARCHAR2 (2 Byte)
    I only want get one record with all columns, only have one clause MAX(END_TIME)
    But the other column have difference value.
    when i use MAX(END_TIME) and GROUP BY USER_ID,PROCESS_ID,CASES,....
    the sql didnot give one record,
    It give many records
    Please help me on this
    Regards
    Saven

    Hi, Saven,
    Sorry, it's unclear what you want.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show your proiblem using commonly available tables, like those in the scott or hr schamas, then you don't have to post any sample data: just the results and the explanation.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}
    Are you trying to see all data related to the highest (that is, latest) end_time?
    I think you want something like this, that finds all the ionformation about the employee with the latest hiredate:
    WITH     got_r_num     AS
         SELECT     emp.*
         ,     ROW_NUMBER () OVER (ORDER BY  hiredate  DESC  NULLS LAST)
                   AS r_num
         FROM     scott.emp
    SELECT     *     -- Or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;What do you want in case of a tie, that is, if 2 or more rows have the same latest end_time? You may need to add tie-breaking expressions to the analytic ORDER BY clause, and/or use RANK instead of ROW_NUMEBR

  • SQL Studio and DB Manager GUI - wrong installers

    There is a bug in these downloads.
    Under DB_Manager_GUI_7_6_Windows_x86_32_bit.exe is installer of SQL Studio, and under SAP_MaxDB_SQL_Studio_7_6_Windows_x86_32_bit.exe is installer of DB Manager GUI respectively.
    Please switch/rename these files. Chris

    Hello,
    1)
    Please review the document at
    http://maxdb.sap.com/doc/7_7/default.htm -> Glossary -> Database Manager
    "SAP MaxDB Database Manager is a database tool for creating and managing databases, database users, and Database Manager operators."
    You could run the SAP MaxDB Database Manager without passwords, but you need the user/pwd information to connect to the database.
    2)
    You could check the default database user's , DBM Operator passwords in MaxDB Library:
    http://maxdb.sap.com/doc/7_7/default.htm -> Glossary -> DBM Operator
    http://maxdb.sap.com/doc/7_7/default.htm -> Glossary -> Database System Administrator
    -> Changing Passwords of Standard Users
    3)
    If you have further questions/problems to connect to your database using Database Manager, please create the new thread. Please post also additional information :
    What is the version of the database instance?
    What SAP MaxDB Database Manager tool you are using < dbmcli ? Database Studio? DBMGUI? > ?
           What version?
    Thank you & best regards, Natalia Khlopina

  • Sum and group by using CAML query

    Is there any way to get the SUM of values with group by ID using CAML query?
    I have a custom list, in that I have ID and Value columns as below
          ID         Value1      Value2
          1             10             4
          2              5              3
          1             15             2
          3             20             1
    I want to get result:
         ID          Value1        Value2
         1             25                6
         2             5                  3
         3             20                1
    I used CAML query:
    <View>
    <Query>
    <Where>
    <IsNotNull>
    <FieldRef Name="ID" />
    </IsNotNull>
    </Where>
    <GroupBy Collapse="FALSE">
    <FieldRef Name="ID" />
    </GroupBy>
    </Query>
    <ViewFields>
    </ViewFields>
    <Aggregations Value="On">
    <FieldRef Name="Value1" Type="SUM" />
    <FieldRef Name="Value2" Type="SUM" />
    </Aggregations>
    </View>
    But
    this query returns all the records
    that satisfy the condition <Where>.
    I
    do not correctly?

    You need to work with current view based aggregation. Please check below threads for your reference.
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/dda5735a-fecf-403f-9495-1b63617d2fbf/question-on-a-caml-query?forum=sharepointdevelopmentlegacy
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/24e88d6a-ee15-4d81-a5fe-504c7bd14e46/how-to-sum-a-column-value-using-caml-query?forum=sharepointdevelopment
    Hope this helps.
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful
    I've seen these
    issues and articles and do them, but
    does not work. I use object mozhel
    Sharepoint (javascript).

  • SQL sentence and GROUP BY

    Hello:
    I have a table with the following facts: ID (autoincrement, primary key), item code, amount, value.
    I must select, FOR EACH item, the last ID (max value), the item code, and the division between value and amount just of the register with the MAX(ID).
    I think I must GROUP BY item, the dicision must appear in the sentence but not GROUPED BY anything.
    Something like this:
    SELECT max(ID), itemcode, value/amount
    FROM tablename
    GROUP BY itemcode
    FOR EXAMPLE, if I have the table
    1 Potatoes 2 1000
    2 Tomatoes 3 300
    3 Tomatoes 2 100
    4 Potatoes 1 4000
    The result should be
    3 Tomatoes 50
    4 Potatoes 4000
    Lots of thanks for your help and excuse me for my los level of SQL!

    Hello:
    I have a table with the following facts: ID
    (autoincrement, primary key), item code, amount,
    value.
    I must select, FOR EACH item, the last ID (max
    value), the item code, and the division between value
    and amount just of the register with the MAX(ID).
    I think I must GROUP BY item, the dicision must
    appear in the sentence but not GROUPED BY anything.
    Something like this:
    SELECT max(ID), itemcode, value/amount
    FROM tablename
    GROUP BY itemcode
    FOR EXAMPLE, if I have the table
    1 Potatoes 2 1000
    2 Tomatoes 3 300
    3 Tomatoes 2 100
    4 Potatoes 1 4000
    The result should be
    3 Tomatoes 50
    4 Potatoes 4000
    Lots of thanks for your help and excuse me for my los
    level of SQL!Your question is not clear. From the sample data and req o/p that you have given i think you want something like this:
    Maximum 2 IDs from a given set of data, their codes and a value => amount/value. Is that what you want?
    Jithendra

  • How to write SQL query and apply aggregate functions on it

    Hello experts,
    Iu2019ve a task to write SQL query on tree tables and do inner join on them. Iu2019ve accomplish this task by using T-CODE SQVI. However now I need to write a query and apply SQL functions on it i.e. Add, Count, Max and Min etc. Please can someone tell me how I can write SQL query with aggregate functions in SAP?
    Thanks a lot in advance

    HI Mr. Cool
    you can see the below code for using aggregate functions.
    where ARTIST and SEATSOCCU are the field names for which you want to perform these functions.
    DATA: TOTAL_ENTRIES TYPE I,
          TOTAL_ATT TYPE I,
          MAX_ATT TYPE I,
          AVG_ATT TYPE I.
    SELECT COUNT( DISTINCT ARTIST )
           SUM( SEATSOCCU )
           MAX( SEATSOCCU )
           AVG( SEATSOCCU ) FROM YCONCERT INTO (TOTAL_ENTRIES, TOTAL_ATT,
    MAX_ATT, AVG_ATT).
    Thanks
    Lalit Gupta

  • SQL limit and group rows

    Hi,
    I have two tables with 1 to n relationship.
    StudentTable
    ==========
    ID NAME
    1 John
    2 Mary
    3 Peter
    SubjectTable
    =========
    SID Subject
    1 Maths
    2 English
    3 Science
    The above two tables are connected with this table
    StudentDetials
    ==========
    ID(Students) SID(Subjects)
    1 1
    1 2
    2 3
    3 2
    3 3
    I want to select data from both tables. But I want to select only one row from SubjectTable for each student, even though there are many rows in SubjectTable for each student.
    Is it possible to do this with SQL.
    Best regards,
    Chamal.

    If you don't care about something specific about this SID's then may be this will help you a bit.
    p.s. sorry it's a little rough, but I didn't want to create any tables :-)
    select * from
    (select id,sid,row_number() over (partition by id order by sid asc) rn
    from (select 1 id,1 sid from dual
    union all
    select 1,2 from dual
    union all
    select 2,3 from dual
    union all
    select 3,2 from dual
    union all
    select 3,3 from dual) t)
    where rn = 1;

  • Sorting and Grouping -Two months in this query

    Hi All,
    many thanks for jeneesh
    i am doing project for construction company, i face this problem in grouping points according to relation between these points the
    Relation is from 1 to 100. If the point between this rang that mean there is relation between these points.
    this question already solve but the results not correct when the table has more data.
    SQL - sorting and grouping.
    from jeneesh and many thanks for him.
    This example for more clarifications
    for example i have these points
    id   location         percentage   comments
    1     loc 1,2          20%                that mean point  1 and 2 close to each other by 20%
    2     loc 1,3          40%              that mean point 1 and 3 close to each other byy 40%
    3     Loc 8,6          25%               that mean point 8 and 6 close to each other by 25%
    4     Loc  6,10        20%
    5     LOC 11,10        10 %
    6     LOC 15,14         0%Also , we can see the relation between these points as follwoing
    - points 1,2,3 in one group why becuase 1,2 has relation and 1,3 has relation that mean 1,3 also has hidden relation.
    - Points 6,8,10,11 in second group there are relations between them .
    - but no relation between 1 or 2 or 3 with any point of 6,8,9,10,11
    - as well as no relation between 15, 14 that mean 14 in third group and 15 in fourth group.
    whati need?
    to group the points that has relation according to percentage value ascending
    The most important part is to group the points. SO , the below query the gropuing is not correct.
    I have the follwoing table with data
    drop table temp_value;
    create table temp_value(id number(10),location varchar2(20), percentage number(9));
    insert into temp_value values  (1,'LOC 1,2',10);
    insert into  temp_value values (2,'LOC 1,3',0);
    insert into  temp_value values (3,'LOC 1,4',0);
    insert into  temp_value values (4,'LOC 1,5',0);
    insert into  temp_value values (5,'LOC 1,6',0);
    insert into  temp_value values (6,'LOC 2,3',0);
    insert into  temp_value  values(7,'LOC 2,4',0);
    insert into  temp_value values (8,'LOC 2,5',30);
    insert into  temp_value values (9,'LOC 2,6',0);
    insert into  temp_value values (10,'LOC 3,4',0);
    insert into  temp_value values (11,'LOC 3,5',0);
    insert into  temp_value values (12,'LOC 4,5',40);
    insert into  temp_value values (13,'LOC 4,6',0);
    insert into  temp_value values (14,'LOC 6,7',40);
    insert into  temp_value values (15,'LOC 7,2',0);
    insert into  temp_value values (16,'LOC 8,2',60);
    insert into  temp_value values (17,'LOC 8,3',0);
    insert into  temp_value values (18,'LOC 3,1',0);
    insert into  temp_value values (19,'LOC 9,6',30);
    insert into  temp_value values (20,'LOC 11,2',0);
    insert into  temp_value values (22,'LOC 12,3',10);
    insert into  temp_value values (23,'LOC 19,3',0);
    insert into  temp_value values (24,'LOC 17,3',0);
    insert into  temp_value values (24,'LOC 20,3',0);when i used this query , the results is not correct
    with t as
        (select percentage,loc1,loc2,sum(case when percentage = 0 then 1
                           when loc1 in (l1,l2) then 0
                       when loc2 in (l1,l2) then 0
                       when l1 is null and l2 is null then 0
                       else 1
                  end) over(order by rn) sm
        from (     select id,location,percentage,
                           regexp_substr(location,'\d+',1,1) LOC1,
                          regexp_substr(location,'\d+',1,2)  LOC2,
                         lag(regexp_substr(location,'\d+',1,1))
                          over(order by percentage desc) l1,
                          lag(regexp_substr(location,'\d+',1,2))
                          over(order by percentage desc) l2,
                  row_number() over(order by percentage desc) rn
          from temp_value
          order by percentage desc
       select loc,min(sm)+1 grp
         from(
           select loc,rownum rn,sm
           from(
           select percentage,decode(rn,1,loc1,loc2) loc,sm
           from t a,
                (select 1 rn from dual union all
                 select 2 from dual ) b
           order by percentage desc,decode(rn,1,loc1,loc2) asc
        group by loc
       order by min(sm),min(rn);the results
    SQL> /
    LOC                         GRP
    2                             1
    8                             1
    6                             2
    7                             2
    4                             3
    5                             3
    9                             4
    1                             5
    12                            6
    3                             6
    11                           13
    LOC                         GRP
    19                           14
    17                           15
    20                           22
    14 rows selected.SQL>
    but the correct is
    Location        group No
    2                  1
    8                  1
    4                  1
    5                  1
    1                  1
    6                  2
    7                  2
    9                  2
    12                 3
    3                  3
    19                 4
    17                 5
    20                 6many thanks in advance.
    Edited by: Ayham on Nov 30, 2012 3:07 AM

    Thanks,
    i want the sorting for each group DESC not all groups to gather
    when i used your query i get
    SQL> with connects as (
      2  select distinct
      3   loc1
      4  ,loc2
      5  ,dense_rank() over (order by connect_by_root(loc1)) grp
      6  from temp_value
      7  start with
      8  percentage != 0
      9  connect by nocycle
    10  (prior loc2 = loc1
    11  or
    12  prior loc1 = loc2
    13  or
    14  prior loc1 = loc1
    15  or
    16  prior loc2 = loc2)
    17  and
    18  percentage != 0
    19  )
    20  ,  got_grp AS
    21  (
    22     select
    23      loc
    24      ,dense_rank() over (order by grp) grp
    25      from (
    26      select
    27       loc
    28       ,max(grp) keep (dense_rank first order by grp) grp
    29       from (
    30       select
    31        loc1 loc
    32        ,grp
    33        from connects
    34        union
    35        select
    36         loc2
    37         ,grp
    38         from connects
    39         )
    40         group by
    41         loc
    42        )
    43  )
    44  SELECT       loc
    45  ,    grp
    46  FROM         got_grp
    47  ORDER BY  COUNT (*) OVER (PARTITION BY grp)   DESC
    48  ,            grp
    49  ,    loc
    50  ;The output is
    LOC                         GRP
    1                             1
    2                             1
    4                             1
    5                             1
    8                             1
    6                             3
    7                             3
    9                             3
    12                            2
    3                             2
    10 rows selected.but i want it like this
    Loc  Grp
    2      1
    8      1
    4      1
    5      1
    1      1
    12    2
    3      2
    6      3
    7      3
    9      3So , the sorting for each group Separate based on the percentage column.
    many thanks
    Edited by: Ayham on Nov 30, 2012 9:43 AM

  • Eliminating NULLs for SUM(current-group)

    I face the following problem:
    I have some NULL values in my data which I elimnated by a <?xdofx:decode(FIELD,'',0,FIELD)?>
    add. I have defined a summary field with <?sum (current-group()/FIELD)?> that results in "NaN" because of the NULLs.
    But decode doesn't work in the sum(c... ) !?
    Any help is appreciated.
    Dirk

    Hi,
    I didn't know about the to_number, that's useful to know.
    It get's a little ugly in your template but you can work around have the sum before the for-each. The answer is to have a for-each purely to create the sum. I've had to do it for a couple of templates.
    I usually put the code in a template to make it easier to read and the not put too much code in to a cell in a table. Try the following:
    <?template:t_sumdata?>
    <?for-each:xxx?>
    <?if:ELEMENT!=''?>
    add to variable
    <?end if?>
    <?end for-each?>
    <?end template?>
    The above code can go anywhere in your template, I normally put them at the end. To reference this just put
    <?call:t_sumdata?><?get variable value?>
    where you want the total to appear.
    Thanks
    Paul

  • SQL query to group data by Code and dates

    Hi There,
    I have the following table structure
    col1 col2 col3
    code1 21-jan-2012 tested
    code1 20-jan-2012 tested
    code1 01-jun-2012 tested
    code2 01-jun-2012 tested
    code3 04-jun-2012 tested
    so on
    The output should be some thing like
    code Week1 week2 week 3 week4 week5 till about last 14 weeks from the date we are running
    code1 1 0 0 0 0
    code2 1 0 0 0 0
    code 3 0 1 0 0 0
    where 1, 0 is actually the counts and not sum and the week in this case, should have maybe been since we are in the second week it should have been
    code .....................week3 may week4 may week1 jun week2june
    Was looking for suggestions on how to get this done.
    I am assuming this would require some sort of a pivot query?
    Thanks,
    Sun

    Hi, Sun,
    sun1977 wrote:
    Thanks EKH,
    Yes, in lines of the output of this query. Is it possible to,
    1. In the query, if condition is met, the it simply displays 1 else 0. Basically, we need to get the count of the number of the codes in that week. So if code 1 happened 5 times, it should show 5.Sure; use COUNT instead of MAX.
    2. Provide the output between two dates. Lets say, I have to do it for the last 14 weeks from sysdate. Then will the logic of week1 = 1 work?Use date arithmetic to get the number of days between the starting date and col2, then divide by 7 to get the number of weeks. Use that number instead of the value returned by TO_CHAR.
    3. any suggestions if the counts have to be changed to percentages. How can we have the percentage value showingYou can do that. Exactly how depends on exactly what you want. It may involve using the analytic RATIO_TO_REPORT function in a sub-query. Post the exact results you want from the sample data that Ekh posted (or new sample data that you post), and explain how you get those results from that data.
    4. Would we also be able to add a date bind value. Lets say, if the user selects start date as may, 1st, 2012 and end date as jun5th. It sort of shows the same data but in weekly format for the weeks between the period selected?Sure, just use those values in a WHERE clause. The output needs to have a fixed number of columns, however. Say that number is 14. You can give a range that only covers 5 weeks, but the output will have 9 0's at the end of every row. You can give a range that covers 15 or more weeks, but the weeks after 14 will not be shown. To get around that requires dynamic SQL (if you want each week in a real column) or string aggregation. See {message:id=3527823}
    Point 3 is different from point 1 as in, the first one would be maybe using your logic but hardcoding for 14 weeks. Point three would be a little more dynamic.
    Thanks for your time.
    Sun
    Edited by: sun1977 on Jun 7, 2012 2:28 AM
    EXEC  :start_dt_txt := '01-May-2012';
    EXEC  :end_dt_txt   := '05-Jun-2012';
    WITH  got_week_num  AS
         SELECT  col1, col2
         ,     1 + FLOOR ( (col2 - TO_DATE (:start_dt_txt, 'DD-Mon-YYYY'))
                         / 7
                     )     AS week_num
         FROM    t
         WHERE     col2     >= TO_DATE (:start_dt_txt, ':DD-Mon-YYYY')
         AND     col2     <  TO_DATE (:end_dt_txt,   ':DD-Mon-YYYY') + 1
    SELECT       col1
    ,       COUNT (CASE WHEN week_num =  1 THEN 1 END)     AS week_1
    ,       COUNT (CASE WHEN week_num =  2 THEN 1 END)     AS week_2
    ,       COUNT (CASE WHEN week_num =  3 THEN 1 END)     AS week_3
    ,       COUNT (CASE WHEN week_num =  4 THEN 1 END)     AS week_4
    ,       COUNT (CASE WHEN week_num =  5 THEN 1 END)     AS week_5
    ,       COUNT (CASE WHEN week_num =  6 THEN 1 END)     AS week_6
    ,       COUNT (CASE WHEN week_num = 14 THEN 1 END)     AS week_14
    FROM       got_week_num
    GROUP BY  col1
    ORDER BY  col1
    ;Edited by: Frank Kulash on Jun 7, 2012 5:53 AM

  • [HELP] AGO function return wrong result

    Hi, i try to implement ago function in OBIEE, but the result is not as expected. Please help me to configure Time Dimension to get this work.
    My case:
    - I have a time dimension with this configuration:
    [http://i264.photobucket.com/albums/ii176/necrombi/NEO/1-1.png]
    Time Hierarchy: Total > Year > Quarter > Month > Day
    Year:
    Primary key: Calendar_year_cal_year_code
    Chronological key: Does not define
    Quarter:
    Primary key: Calendar_quarter_description
    Chronological key: Does not define
    Month:
    Primary key: Calendar_month_description
    Chronological key: Calendar_month_description
    Day:
    Primary key: Dimension_key
    Chronological key: Day_day_code
    My ago function: AGO(expression, mywh.D_qn_thoigianDim."month", 1)
    I do not understand why i get this wrong results:
    [http://i264.photobucket.com/albums/ii176/necrombi/NEO/2.png]
    Does anyone know how to solve this?
    Edited by: 864451 on Jun 8, 2011 5:11 AM

    Hi, thanks for your reply.
    I implemented Time dimension with your recommend, and have time dimension like this:
    Time Hierarchy: Total > Year > Quarter > Month > Day
    Year:
    Primary key: Calendar_year_start_date
    Chronological key: Calendar_year_start_date
    Quarter:
    Primary key: Calendar_quarter_start_date
    Chronological key: Calendar_quarter_start_date
    Month:
    Primary key: Calendar_month_start_date
    Chronological key: Calendar_month_start_date
    Day:
    Primary key: Day
    Chronological key: Dimension_key
    And Ago function works fine with month level: AGO(expression, mywh.D_qn_thoigianDim."month", n)
    But return sum result of 12 month with: AGO(expression, mywh.D_qn_thoigianDim."year", 1)
    In my case, i just use AGO(expression, mywh.D_qn_thoigianDim."month", 12) to get year ago value. But i still don't understand clearly about OBIEE Time Serries functions.
    Thanks,
    Dung Nguyen

  • Avoid procedure or function calls between a SQL operation and an implicit cursor test

    when i analyse this code with code expert

    atpidgeon wrote:
    when i analyse this code with code expert
                            UPDATE P_PM_CONTROL_COUNT
                            SET AVAIL_SEG = AVAIL_SEG -1,
                                ALLOCATION = ALLOCATION -1
                            WHERE PM_UNIT_TYPE_ID = vrectab(1)
                            AND USAGE_DATE = vrectab(2)
                            AND SEGMENT_CODE = vrectab(5)
                            AND ALLOCATION - UNITS_RESERVED > 0;
                            IF sql%rowcount = 0 then --Added block and exception to prevent invetory going negative when placing multi units in same unit type out of service.
                                vErrMsg := 'Could not process your out of service request because your selection for unit '|| vrectab(3) || ' at ' || pvPropertyId || ' for ' || vrectab(2) || ' would cause segment ' || vrectab(5) || ' to be over allocated.';
                                RAISE SegOverAllocated;
                            END IF;
    i get "Avoid procedure or function calls between a SQL operation and an implicit cursor test.",as far has i know
    iff you're doing a sql%rowcount    after an update.. trying to see how many rows were updated...  you dont want procedure or function calls between the update and the sql% line
    correct me if im wrong and how would i fix it?or maybe i shouldnt
    You correct it by NOT executing function calls as part of the UPDATE statement.
    1. Issue the function calls BEFORE the update statement
    2. save the function results into variables
    3. use those variables in the UPDATE statement.
    v_rectab1 := vrectab(1);
    v_rectab2 := vrectab(21);
    v_rectab5 := vrectab(5);
    UPDATE P_PM_CONTROL_COUNT 
                            SET AVAIL_SEG = AVAIL_SEG -1,
                                ALLOCATION = ALLOCATION -1
                            WHERE PM_UNIT_TYPE_ID = v_rectab1
                            AND USAGE_DATE = v_rectab2
                            AND SEGMENT_CODE = v_rectab5
                            AND ALLOCATION - UNITS_RESERVED > 0;

  • Group by function use in sql

    I want to get an output using group by function of there is no data in the table to display a particular value
    for eg:
    SELECT TRUNC(updated_date) DATE1 , COUNT(1) COUNT FROM table
    where TRUNC(updated_date) >=TRUNC(SYSDATE-18) AND TRUNC(updated_date) <=TRUNC(SYSDATE)
    GROUP BY TRUNC(updated_date)
    ORDER BY TRUNC(updated_date) DESC;
    DATE1 COUNT
    6/16/2012 14208
    6/15/2012 307825
    6/14/2012 172988
    6/6/2012 138790
    6/5/2012 167562
    6/4/2012 51870
    6/2/2012 130582
    6/1/2012 239806
    But i need the missed out date i.e 6/3/2012 - 0, 6/7/2012 - 0 to be displayed since there is no data on the repective dates.

    Hi,
    You can only display things that are in a table (or result set, but from now on, I'll just say table), or that can be derived from a table. If you want to display dates that are not in your table, then you have to get them from another table, or derive them from some table.
    Some people actually keep tables of possible dates for queries like this. In this case, all you need is a table of the last 19 dates, ending with today. That's easy to derive from dual:
    WITH     all_dates     AS
         SELECT     TRUNC (SYSDATE)     - LEVEL     AS date1
         ,     TRUNC (SYSDATE) + 1 - LEVEL     AS date2
         FROM     dual
         CONNECT BY     LEVEL <= 19
    SELECT    a.date1
    ,        COUNT (x.updated_date)     AS count
    FROM                all_dates     a
    LEFT OUTER JOIN    table_x     x  ON     x.updated_date     >= a.date1
                                AND     x.updated_date     <  a.date2
    GROUP BY  a.date1
    ORDER BY  a.date1
    ;If you'd care to post CREATE TABLE and INSERT statements for some sample data, and the results you want from that data, then I could test this.

  • Are the Pl/sql procedure and function atomic by themself

    i want to ask a question does oracle pl/sql procedure and function support Atomicity for the database by themself , or they became atomic incase we call them using begin -- end;

    You appear to be discussing transaction scope which is completely independent of PL/SQL blocks like procedures or how you call procedures. It's all in where commits (or rollbacks) are issued.
    If you have a procedure like this
    CREATE PROCEDURE p1
    AS
    BEGIN
      INSERT INTO some_table( key, value ) VALUES( 1, 'Foo' );
      INSERT INTO some_table( key, value ) VALUES( 1, 'Bar' );
    END;where the first statement succeeds and the second statement fails as a result of a duplicate key, there will still be a Foo row in the table but the procedure will have thrown an exception. The caller of the procedure may choose to commit or rollback the change-- that will determine whether the first statement's results are made permanent. If you have a procedure like this,
    CREATE PROCEDURE p1
    AS
    BEGIN
      INSERT INTO some_table( key, value ) VALUES( 1, 'Foo' );
      commit;
      INSERT INTO some_table( key, value ) VALUES( 1, 'Bar' );
    END;the commit will make the first insert permanent regardless of whether the second statement fails no matter what the calling code does (that's one reason that putting commits in stored procedures is generally a bad idea-- the caller is in a much better position to know what other uncommitted work has been done and whether it is safe to commit.
    Justin

Maybe you are looking for

  • Saving PDF form on Mac prevents viewing and printing by another viewer

    We run a student competition which is affiliated with a national competition.  The national competition provides a set of forms that must be filled out by the students, teachers, etc.  We have a process set up whereby students can download a PDF form

  • Question Related To Dates

    Hi All, I have been knocked off by this strange situation. I will try to simplify and explain the problem at my best. We have DATE column in a table, the data ranging from 01-Jan-2009 to 31-12-2010. We have to calculate ISO_WEEKS based on the date co

  • Browse Folder Dialog in JSP

    Hi Everybody! I have a user-form within an JSP, and within this I want the user to specify a folder an his system. I already tried <input type="file" .... > But with this tag you can only select a specific file, not a folder. Now I solve the problem

  • How do I remove FBI ransomware from Safari

    How do I remove FBI ransomware from Safari

  • Material Needed on Data Migration

    Hi All,                I am working on project as fresher.                The major work is on Data Migration.                                 Can I have get any material like Basic documents,                Sample programs/Codes Concept explanation