Consecutive days of absence

Experts.
I have a query request using InfoSource 0HR_PT_2.  (data volume is extremely large with this extractor.)
Business has 100k employees.
Client wants to see which persons have consecutive absences >= 20 days.  (NOT 20 days or more total)
I have the restrictions on TYPES or ABSENCE and Users have not defined the periods of their search. (month to month, year to year?) 
How can I count hours / days of data that sum up to 20 consecutive days?
Thanks for any suggestions, both backend or query based.
Steve

Experts.
I have a query request using InfoSource 0HR_PT_2.  (data volume is extremely large with this extractor.)
Business has 100k employees.
Client wants to see which persons have consecutive absences >= 20 days.  (NOT 20 days or more total)
I have the restrictions on TYPES or ABSENCE and Users have not defined the periods of their search. (month to month, year to year?) 
How can I count hours / days of data that sum up to 20 consecutive days?
Thanks for any suggestions, both backend or query based.
Steve

Similar Messages

  • Count consecutive days in array

    Hi,
    I'm looking for an algorithm to count consecutive days in array, but i don't find one.
    for example, if i have this array.
    2009/07/01
    2009/07/02
    2009/07/03
    2009/07/06
    2009/07/08
    2009/07/09
    2009/07/10
    2009/07/11
    The result be
    3
    1
    4
    Anyone have one?
    Thanks for all.

    jverd wrote:
    kajbj wrote:
    It's a fairly specialist algorithm so you are unlikely to find someone to post a solution. By just keeping a reference to the previous date, it is easy to iterate though the list counting consecutive dates.I think the trick to making this algorithm sucessful is to make sure that when you change months your algorithm doesn't set consec_days to 0 Why not?Presumably he's talking about this case:
    7/31
    8/1
    and not this case
    7/1
    8/1
    So he really should have said, "...when you increment month by one, or from 12 to 1, and the day went from the last day of the old month to 1, don't set consec_days to 0"Ok. I would use the Calendar class and SimpleDateFormat. The tricky part would otherwise be to keep track of days per month, and leap year.

  • How to find consecutive days?

    Hi I have a requirement, where I need to find all employees who have taken 5 consecutive days off in one week.
    I am trying to build a query in BI, which can identify these records, but of no avail. I am wondering if I can do this in visual Composer. My data output currently looks like this in a table.
    Employee number     calendar day    time-off hours
      100                           6/8/2009         8
      100                           6/9/2009         8
      100                           6/10/2009       8
      100                           6/11/2009       8
      100                           6/12/2009       8
      101                           6/1/2009         8
      101                           6/5/2009         8
      I like to loop through this table, somehow, and identify that employee 100, has 5 consecutive days off, but not 101.
      I like to filter those employees who do not have 5 consecutive days off, and just show those who have 5 days off, like employee number 100. My output should look like, this
    Employee number     calendar day    time-off hours
      100                           6/8/2009         8
      100                           6/9/2009         8
      100                           6/10/2009       8
      100                           6/11/2009       8
      100                           6/12/2009       8
    Any ideas will be greatly appreciated. I am trying out dynamic expression, but cannot find a way to access the first row of data, while processing the second row.

    Hi
    Why dont you try with time characteristics '0CALWEEK'. Add '0CALWEEK' to your infocube & map it with the date which you already have in the table. Now consider the your example for employee '100' -
    100 6/8/2009 8
    100 6/9/2009 8
    100 6/10/2009 8
    100 6/11/2009 8
    100 6/12/2009 8
    by adding Calweek you will get - 100   24.2009 (that is 24 th week)  40 hrs.
    Now in your query divide this 40 hrs (that is total working hours in week) with daily min working hrs. (In your case assume it 8 Hrs per day). So in query you will get number of working days in a week for each employee. From this you can easily find out how many leaves each employee has taken.
    I think this is what you are looking for.
    Regards
    Sandeep

  • App Hangs in 3 consecutive days

    Hi all,
    11.2.0.1
    Aix 6.1
    Our database & app hangs for the first time, 3 consecutive days (Aug 11,12,13)  during run of batch jobs at 12AM.
    The batch operator said the batch job is deleting a table with only less than 1000 rows but was not able to lock the table as there lots of updates queues from lots of client app.
    I check the alert log for the said time period and this is the output. I saw similar occurences at 1AM
    Tue Aug 13 01:20:45 2013
    Clearing standby activation ID 2855092487 (0xaa2d4107)
    The primary database controlfile was created using the
    'MAXLOGFILES 16' clause.
    There is space for up to 10 standby redo logfiles
    Use the following SQL commands on the standby database to create
    standby redo logfiles that match the primary database:
    ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 262144000;
    ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 262144000;
    ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 262144000;
    ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 262144000;
    ALTER DATABASE ADD STANDBY LOGFILE 'srl5.f' SIZE 262144000;
    ALTER DATABASE ADD STANDBY LOGFILE 'srl6.f' SIZE 262144000;
    ALTER DATABASE ADD STANDBY LOGFILE 'srl7.f' SIZE 262144000;
    Tue Aug 13 02:00:00 2013
    Closing scheduler window
    Closing Resource Manager plan via scheduler window
    Clearing Resource Manager plan via parameter
    Tue Aug 13 04:36:07 2013
    WARNING: Heavy swapping observed on system in last 5 mins.
    pct of memory swapped in [9.53%] pct of memory swapped out [23.33%].
    Please make sure there is no memory pressure and the SGA and PGA
    are configured correctly. Look at DBRM trace file for more details.
    Tue Aug 13 05:07:14 2013
    Thread 1 cannot allocate new log, sequence 49033
    Private strand flush not complete
    AlertSunday Aug 11
    https://app.box.com/s/6ut7uk0o5y6tg2sjfzvn
    AlertMonday Aug 12
    https://app.box.com/s/gafa2d1ngn7hpen6tfky
    AlertTuesday Aug 13
    https://app.box.com/s/o5v5gtul1mr3yra6vbgj
    Do you have any idea what causes tha hang? Its weird because these did not happened before.
    Please help...
    Thanks a lot,
    zxy

    Thanks,
    Does these ASH, & AWR reports shows anything?
    ASH
    https://app.box.com/s/bmuafe2y39mzo036bbij
    https://app.box.com/s/jdfv3uauwhp7tttvqlig
    https://app.box.com/s/7r0sej0r77n3jay7n1fd
    AWR
    https://app.box.com/s/fdyx0rare2tskd291f1w
    https://app.box.com/s/0pd4u7kzt0p10rhgnivq
    https://app.box.com/s/sjotdxe57pssjitabrj2
    Thanks,

  • Single Class Split Over multiple non-consecutive Days??

    How do I setup in OLM  a class split over multiple days for Example:
    I have a Diversity Awareness Course and Offering. The Class is 2 days long, but not on consecutive days, they are a week apart.
    Do I create a Day1 Class and Day2 class under the same course and make it a prerequisite to attend day 1?
    From a reporting point of view this now shows as 2 classes when it is only 1; inflating the class figures.
    Or Can I split it into 2 sessions under the same class?
    What is the best way to do this?

    Hi!
    You can create a Class with two Sessions underneath it (one for each day).  Make the Start Date for the Class the day the Class begins and set the End Date to correspond to the last day.  Your Duration should be set to 2 Days.  Learners will be able to view details for each session, and you can assign different instructors and rooms for each day if you use Resource Bookings in OLM.
    Anne
    Anne Saulnier | Synergy Codeworks LLC
    [email protected]
    603-864-9942

  • Birthday from calendar appears on two consecutive days when synced with iPo

    Hello.
    This has utterly confounded me.

    Hello, tt2.
    My original post appeared twice because somehow I managed to click the wrong command before I finished it the first time. Either that or the cat walked across the keyboard!
    Each birthday and anniversary in my iCal is set for 'all day', from and to the same date, to repeat annually and end never, but this is the only one that is in iCal for one day a year, yet on the iPod for two consecutive days a year.
    I've removed all calendar files from the iPod manually and then re-synced, but the problem persists.
    Thanks.

  • Select non-consecutive days in Calendar input

    Hi Experts,
    I designed a form in WD and have a requirement, where I need to show up a calendar display of months in which an user should be allowed to select only non-consecutive days from it.
    Also I need to get all those selected days at run-time.
    Is it possible?? I know that calendar is a standard input of date UI element and totally confused as how I can restrict an user to select only non-consecutive days.
    Please clarify and help me in this.
    BR,
    RAM.

    Hi RAM,
    Unfortunately, with the date navigator ui element, we cannot select multiple dates except the date ranges.
    Work around solution:
    I suggest you to go for row repeater, in which you can place date navigator ui element and user can add multiple rows: also you he can input dates by selecting single dates.
    Here you can also restrict the user to select only non-consecutive dates.
    Pls refer the wiki for an example:
    steps to create row repeater ui element - Web Dynpro ABAP - SCN Wiki
    Try to convince the user with this or you can also for a table with single row.
    Hope this helps you.
    Regards,
    Rama

  • Latest Number of Consecutive Days ("Current Streak")

    Using SQL Server (On Azure)
    I am trying to figure out how to get the latest number of consecutive days in an SQL query.
    I have a habit tracking app in which I keep track of best streaks, originally I was storing this "Streak" value as it's own column in the Habit table and changing it directly. This of course led to incorrect syncing and accuracy issues. I realize
    the best way to do it is to calculate from existing data.
    I simplified the 2 tables as listed below:
    Habit
    id (the habit id)
    Name (the name of the habit)
    Target (the target number of entries required to be considered completed)
    HabitEntry
    id (the habit entry id)
    HabitID (the corresponding habit id)
    EntryDate (the date and time of the entry)
    Looking to get a query that looks something like this:
    SELECT habit.id, habit.Name, (*subquery*) as 'CurrentStreak' from habit join habitentry on habit.id = habitentry.habitid
    And outputs something like this:
    1, 'Exercise Daily', 7
    If the habit's target is 2, there must be 2 entries within that date to be considered completed and to add to the streak.
    Not sure if this complicates things, but days are measured from 3:00am to 3:00am, any help is greatly appreciated.

    Figured I'd throw this in just for the fun of it. :)
    IF OBJECT_ID('tempdb..#Habbit') IS NOT NULL DROP TABLE #Habbit
    CREATE TABLE #Habbit (
    ID INT PRIMARY KEY,
    Name VARCHAR(255),
    [Target] INT
    INSERT #Habbit (ID,Name,Target) VALUES
    (1,'Three Day Thing', 3),
    (2,'Four Day Thing', 4),
    (3,'Five Day Thing', 5)
    --=============================================
    IF OBJECT_ID('tempdb..#HabitEntry') IS NOT NULL DROP TABLE #HabitEntry
    CREATE TABLE #HabitEntry (
    UserID INT,
    HabbitID INT,
    EntryDate DATETIME
    INSERT #HabitEntry (UserID,HabbitID,EntryDate) VALUES
    (1, 1, '20150101 06:35:30'),
    (1, 1, '20150102 08:35:30'),
    (1, 1, '20150103 08:35:30'),
    (1, 1, '20150110 09:35:30'),
    (1, 1, '20150112 10:35:30'),
    (1, 1, '20150115 22:35:30'),
    (1, 1, '20150116 23:35:30'),
    (1, 1, '20150117 00:35:30'),
    (1, 1, '20150118 01:35:30'),
    (1, 1, '20150122 04:35:30'),
    (1, 1, '20150124 05:35:30'),
    (1, 1, '20150126 15:35:30'),
    (1, 1, '20150127 10:35:30'),
    (2, 3, '20150101 06:35:30'),
    (2, 3, '20150102 06:35:30'),
    (2, 3, '20150103 02:35:30'),
    (2, 3, '20150104 06:35:30'),
    (2, 3, '20150105 06:35:30'),
    (2, 3, '20150108 06:35:30'),
    (2, 3, '20150110 06:35:30'),
    (2, 3, '20150111 06:35:30'),
    (2, 3, '20150112 06:35:30'),
    (2, 3, '20150113 06:35:30'),
    (2, 3, '20150114 06:35:30'),
    (2, 3, '20150122 06:35:30'),
    (2, 3, '20150123 06:35:30')
    --=============================================
    DECLARE @MinDate DATE, @RangeSize INT
    SELECT @MinDate = DATEADD(dd, -1, MIN(he.EntryDate)) FROM #HabitEntry he
    SELECT @RangeSize = DATEDIFF(dd, @MinDate, MAX(he.EntryDate) + 1) FROM #HabitEntry he
    IF OBJECT_ID('tempdb..#CalRanges') IS NOT NULL DROP TABLE #CalRanges
    SELECT TOP (@RangeSize)
    DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)), @MinDate) AS [Date],
    DATEADD(hh, 3, DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)), CAST(@MinDate AS DATETIME))) AS BegRange,
    DATEADD(hh, 27, DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)), CAST(@MinDate AS DATETIME))) AS EndRange
    INTO #CalRanges
    FROM sys.all_objects ao
    --=============================================
    ;WITH cte AS (
    SELECT
    cr.Date,
    he.UserID,
    he.HabbitID,
    he.EntryDate,
    COALESCE(LAG(CASE WHEN he.EntryDate IS NOT NULL THEN cr.Date END, 1) OVER (PARTITION BY he.UserID, he.HabbitID ORDER BY cr.Date), '19000101') AS PrevDate
    FROM
    #CalRanges cr
    JOIN #HabitEntry he
    ON he.EntryDate BETWEEN cr.BegRange AND cr.EndRange
    --AND he.UserID = 1
    ), cte2 AS (
    SELECT
    c.*,
    CASE WHEN DATEDIFF(dd, c.PrevDate, c.Date) <> 1 THEN ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) END ConseqGroup
    FROM cte c
    WHERE c.Date <> c.PrevDate
    ), cte3 AS (
    SELECT
    c2.*,
    CAST(SUBSTRING(MAX(CAST(c2.Date AS BINARY(4)) + CAST(c2.ConseqGroup AS BINARY(4))) OVER (PARTITION BY c2.UserID, c2.HabbitID ORDER BY c2.Date), 5, 4) AS INT) AS ConseqGroupFill
    FROM cte2 c2
    ), cte4 AS (
    SELECT
    c3.UserID,
    c3.HabbitID,
    h.Name AS HabbitName,
    MIN(c3.EntryDate) AS BegDate,
    MAX(c3.EntryDate) AS EndDate,
    COUNT(*) AS DaysInSeries
    FROM
    cte3 c3
    JOIN #Habbit h
    ON c3.HabbitID = h.ID
    GROUP BY
    c3.UserID,
    c3.HabbitID,
    c3.ConseqGroupFill,
    h.Name
    HAVING
    COUNT(*) >= MAX(h.Target)
    -- SELECT * FROM cte4
    SELECT
    c4.*
    FROM (SELECT DISTINCT he.UserID, he.HabbitID FROM #HabitEntry he) AS a
    CROSS APPLY (
    SELECT TOP 1
    FROM cte4 c4
    WHERE a.UserID = c4.UserID
    AND a.HabbitID = c4.HabbitID
    ORDER BY c4.BegDate DESC
    ) c4
    HTH,
    Jason
    Jason Long

  • Find Employee Worked 7 Consecutive days

    Hello All,
    I have a view with following columns
    (EMP #, Dept #, Total hours worked, Date of the total hours, Current Pay period st date, Current Pay period end date, Previous pay period start date, Previous pay period start date, Next pay period st date, next pay period end date)
    I need a query to find employees who worked consecutively for 7 Days
    within a date range.
    Please let me know...
    Thanks,
    Kottee
    kotteeswaran

    DECLARE @StartDate DATETIME
    DECLARE @EndDate  DATETIME
    SET @StartDate = '11/1/2010'
    SET @EndDate ='11/10/2010'
    SELECT        VP_ALLTOTALS.PERSONNUM,
            MIN(VP_ALLTOTALS.APPLYDATE) AS StartDate,
            MAX(VP_ALLTOTALS.APPLYDATE) AS Enddate
    FROM        (
                SELECT    V.PERSONNUM,
                    V.APPLYDATE,
                    DATEDIFF(DAY, '17530101', VP_ALLTOTALS.APPLYDATE) - ROW_NUMBER() OVER (PARTITION BY VP_ALLTOTALS.PERSONNUM ORDER BY VP_ALLTOTALS.APPLYDATE) AS GroupID
                FROM    VP_ALLTOTALS V
                WHERE    VP_ALLTOTALS.APPLYDATE BETWEEN @StartDate AND @EndDate
            ) AS t
    GROUP BY    VP_ALLTOTALS.PERSONNUM,
            GroupID
    HAVING        COUNT(*) >= 7
    I'm getting following errors
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.PERSONNUM" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.PERSONNUM" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.PERSONNUM" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "VP_ALLTOTALS.APPLYDATE" could not be bound.
    And Many Thanks for PESO and RAMIREDDY...
    Thanks,
    kotteesh
    kotteeswaran

  • 3 days continous absence

    Dear All,
    I am doing an Implementation project.My client has this scenario.
    IF AN EMPLOYEE IS CONTINUOUSLY ABSENT FOR 3 DAYS, ONLY HIS CONVEYANCE(only One WT should be deducted) SHOULD BE DEDUCTED.
    WE HAVE created an absence type which will deduct only conveyance. but how to communicate the system to automatically deduct this WT
    when there is a continuous absence for 3 days.
    Please suggest me.
    Thank you in advance!!!
    Smitha

    Hi Smitha ,
    You have to approach abaper on this. Whenever there there is continuous absence for 3 days for an employee there should be a deduction of Conveyance Wage type
    Take a help of abaper to meet your requirement
    Hope you configured LOP
    When we record absence type through date that is 01.01.2014 till 03.01.2014  that is continuous absence
    when there is no continuous absence among dates the system shouldn't consider deduction of wage type
    when there is continuous absent it should deduct conveyance wagetype, ABAPER can build a logic based on this

  • XY graph crashes after about 3 consecutive days running

    XY graph is getting 720 points a day. My program tries to erase XY graph each day by setting it to zero to avoid memory program. But it crashes every 2-3 day.

    From what you say, there shouldn't be any memory leak issues, and the rate at which you're collecting data shouldn't be causing any trouble. Likewise the amount of data you're plotting is really rather modest.
    Ok, Step 1: Write a replacement subVI that is a drop in replacement for the DAQ subVI and generates the 6 values at the exact same rate, but uses a random number generator to produce the datavalues. Insert this dummy into your code instead of the DAQ and let it run. This will isolate one large part of the code and a good approach in troubleshooting something like this is always "divide and conqure".
    If this version works without crashing, you know its in the DAQ somewhere. If it still crashes, you have something that other people c
    an look at and try to verify there isn't something hinky going on with your PC (Step 2).
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Leave Req - workflow - leave days and absence hours

    Hi,
    For a leave request in workflow, how do i read the leave days (total number of leave) and absense hours from the workflow container? Which fields give that information?
    Regards

    Hi Partha Kar,
    These Links are useful to You,
    [Leave request example in workflow]
    [Re: Employee Leave Request]
    [Leave request auto approvals]
    Regards,
    Raghava Channooru

  • Consecutive Absent Days  Query.. Pls Help Gurus

    I have a table which stores attendance information
    For eg:
    Emp_No Date
    100 01-APR-2010
    102 05-APR-2010
    100 02-APR-2010
    I need a query with parameter From Date and To date..
    My Query Output should be like this .. considering that employee 100 is absent for 8 consecutive days and employee number 102 is absent for 2 consecutive days..
    It should return number of consecutive days he is absent.
    Empno Consecutive Days
    100 8 Days
    102 2 Days
    Pls Help Gurus.
    Edited by: suzvino on Jun 21, 2010 12:14 AM

    TUBBY_TUBBZ?with data as
      2  (
      3     select 100 as emp_no, to_date('01-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      4     select 102 as emp_no, to_date('05-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      5     select 100 as emp_no, to_date('02-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      6     select 100 as emp_no, to_date('01-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      7     select 100 as emp_no, to_date('03-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      8     select 100 as emp_no, to_date('04-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      9     select 100 as emp_no, to_date('05-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    10     select 100 as emp_no, to_date('06-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    11     select 100 as emp_no, to_date('07-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    12     select 100 as emp_no, to_date('08-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    13     select 100 as emp_no, to_date('09-APR-2010','dd-mon-yyyy') as absent_date from dual
    14  )
    15  select
    16     emp_no, max(level)
    17  from data
    18  connect by prior emp_no = emp_no and prior absent_date = absent_date - 1
    19  group by emp_no
    20  having max(level) >= 8;
                EMP_NO         MAX(LEVEL)
                   100                  9
    1 row selected.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?Think i misread the post, so the query should be
    TUBBY_TUBBZ?with data as
      2  (
      3     select 100 as emp_no, to_date('01-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      4     select 102 as emp_no, to_date('05-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      5     select 100 as emp_no, to_date('02-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      6     select 100 as emp_no, to_date('01-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      7     select 100 as emp_no, to_date('03-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      8     select 100 as emp_no, to_date('04-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      9     select 100 as emp_no, to_date('05-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    10     select 100 as emp_no, to_date('06-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    11     select 100 as emp_no, to_date('07-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    12     select 100 as emp_no, to_date('08-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    13     select 100 as emp_no, to_date('09-APR-2010','dd-mon-yyyy') as absent_date from dual
    14  )
    15  select
    16     emp_no, max(level)
    17  from data
    18  connect by prior emp_no = emp_no and prior absent_date = absent_date - 1
    19  group by emp_no;
                EMP_NO         MAX(LEVEL)
                   100                  9
                   102                  1
    2 rows selected.
    Elapsed: 00:00:00.01Edited by: Tubby on May 30, 2010 11:00 PM
    Added second query since i misread the post originally.

  • How to get the account numbers which maintains negative balance for consecutive 5 days

    Here is what I am trying to do 
    I am trying to get the accounts which has negative balance consecutively for five days
    Here in this a/c 1 and 5 has consecutive negative balance
     how to pull these accounts using sql query. 
    create table #p(cal date, ac# int, bal int)
    insert into #p values  ( GETDATE(), 1, -1),
                           ( GETDATE(), 2, 1),
                           ( GETDATE(), 3, 1),
                           ( GETDATE(), 4, -2),
                           ( GETDATE(), 5, -6),
                           ( GETDATE()-1, 1, -1),
                           ( GETDATE()-1, 2, 1),
                           ( GETDATE()-1, 3, 1),
                           ( GETDATE()-1, 4, 2),
                            ( GETDATE()-1, 5, -7),
                            ( GETDATE()-2, 1, -2),
                           ( GETDATE()-2, 2, -1),
                           ( GETDATE()-2, 3, -1),
                           ( GETDATE()-2, 4, 2),
                           ( GETDATE()-2, 5, -6),
                           ( GETDATE()-3, 1, -2),
                           ( GETDATE()-3, 2, -1),
                           ( GETDATE()-3, 3, -1),
                           ( GETDATE()-3, 4, 2),
                           ( GETDATE()-3, 5, -2),
                           ( GETDATE()-4, 1, -4),
                           ( GETDATE()-4, 2, 1),
                           ( GETDATE()-4, 3, 1),
                           ( GETDATE()-4, 4, -2),
                           ( GETDATE()-4, 5, -2),
                           ( GETDATE()-5, 1, -4),
                           ( GETDATE()-5, 2, 1),
                           ( GETDATE()-5, 3, 1),
                           ( GETDATE()-5, 4, 2),                       
                           ( GETDATE()-5, 5, -1)
                         --  drop table #p

    @ Jing
    Again not sure if it is ok to comment on other people's answers, I hope you don't take it the wrong way, but your query will not account for CONSECUTIVE days. E.g. if the acc balance goes back to a positive value, day count must be reset.
    Now I understand why people answered this so much faster than me LOL.
    Edit: Besides, the requeriment for the acc being returned is that its value was negative for 5 days (120 hours). When a given account balance first switches to a negative value, it has 0 hours in that state. It all add a day to its "negative balance consecutive
    day count" property the next time its value is checked (cal + 1). With that said, if your query worked, it would be cnt > 6 not cnt > 5.
    Thanks for pointing the issue. I have improved my query  to address it.
     I try to come up with something to my understanding to the questions. It may not interpret right  from the question itself for various reasons.  I still consider it is a great learning experience.   Thank you for your comments.
    create table #p(cal date, ac# int, bal int)
    insert into #p values ( GETDATE(), 1, -1),
    ( GETDATE(), 2, 1),
    ( GETDATE(), 3, 1),
    ( GETDATE(), 4, -2),
    ( GETDATE(), 5, -6),
    ( GETDATE()-1, 1, -1),
    ( GETDATE()-1, 2, 1),
    ( GETDATE()-1, 3, 1),
    ( GETDATE()-1, 4, 2),
    ( GETDATE()-1, 5, -7),
    ( GETDATE()-2, 1, -2),
    ( GETDATE()-2, 2, -1),
    ( GETDATE()-2, 3, -1),
    ( GETDATE()-2, 4, 2),
    ( GETDATE()-2, 5, -6),
    ( GETDATE()-3, 1, -2),
    ( GETDATE()-3, 2, -1),
    ( GETDATE()-3, 3, -1),
    ( GETDATE()-3, 4, 2),
    ( GETDATE()-3, 5, -2),
    ( GETDATE()-4, 1, -4),
    ( GETDATE()-4, 2, 1),
    ( GETDATE()-4, 3, 1),
    ( GETDATE()-4, 4, -2),
    ( GETDATE()-4, 5, -2),
    ( GETDATE()-5, 1, -4),
    ( GETDATE()-5, 2, 1),
    ( GETDATE()-5, 3, 1),
    ( GETDATE()-5, 4, 2),
    ( GETDATE()-5, 5, -1),
    ( GETDATE()-6, 5, -1)
    --update #p
    -- set bal=-1*bal
    -- where cal='2014-09-22' and [ac#]=5
    ;with mycte as ( Select *
    ,row_number() Over(Order by [ac#], cal) - row_number() Over(Partition by [ac#], sign(bal) Order by [ac#], cal) rnDelta
    from #p)
    ,mycte1 as (
    select * ,
    sum(Case when bal< 0 Then 1 Else 0 End) Over(Partition by [ac#], rnDelta Order by [ac#],cal ) cnt
    from mycte
    SELECT distinct [ac#] from mycte1
    Where cnt>=5
    drop table #p

  • Auto Calculation of Calendar and absence day on 2001 screen.

    dear gurus
    I have half day absent type Z108, subtype of 2001.
    i want to default calender days on 2001 screen.
    I mean, when user select to create Half day leave/absent on 2001 and subtype z108,
    calendar day and absence should be calculated 0.5 automatically.
    I have worked with T554L,V_554S_G,V_T554E,V_T554C,T556 but didnt work
    at this moment, I am getting this on 2001 screen
    Absence hours                8,00
    Absence days                 1,00
    Calendar days                1,00
    when select Z108.
    I want above 3 as
    Absence hours                4,00
    Absence days                 0,50
    Calendar days                0,50
    kindly help in this scenario.

    Hi Monam,
    Can yuou check the view V_T554S for your absence type.
    The minimum duration and maximum duration in 'Input Chceks' Box should be '000' and '999'.
    Minimum duration in days                                                                               
    The Minimum duration in days defines the minimum permitted duration of
        an attendance or absence.                                                                               
    Attendances and absences that are allowed to last for less than one   
        workday are assigned the indicator 000. Attendances and absences that 
        are to be rejected by the system if they are shorter than one day are 
        denoted by an indicator greater than or equal to 001.                                                                               
    Dependencies                                                                               
    In the Unit field, you determine which of the three durations in days 
        should be used for the validation.                                    
    Thanks & Regards, Swapnil Mishra

Maybe you are looking for

  • Import and print a PDF file

    I'm using a SAPSCRIPT to printout documents (as production orders). And I need to attach a PDF file to this document . The only way I found, is to export the PDF file to PCL file and then import it  as a STANDARD TEXT (so to include it in the SAPSCRI

  • IDOC generation in SAP R/3

    Hi, I want to know how to generate the IDOC for MATMAS?? Regards suman

  • Screenshots save as png not pdf

    Screenshots (using shift+apple+4) save as png files instead of pdf. Png blows; they're fuzzy, unreadable and generally makes the handiness of screenshot a waste of time Someone suggested using the new GRAB feature but it's no better. Anyone know how

  • Issue with Project specific stylesheets

    Hi all, I was watching the thread Project specific stylesheets, and i think i follow all the steps but I can see any change on my WD app. I did the following: 1.- Create a custom portal display, this generates a new entry inside usr\sap\J2E\JC00\j2ee

  • Can't find videos which were uploaded via iCloud from my iPhone to my IPad

    I am new.  I uploaded some photos and videos via iCloud from my iPhone to my IPad , but can't find the videos, but the pictures were there.