Date overlapped
Hi guys, how I can see with one query if I got date overlapped? That's the scenario:
Create table tabletest ( iddd int, datefrom datetime2, dateto datetime2)
insert into tabletest values (1, '2014-01-01', '2014-02-06'),
(2, '2014-01-01', '2014-03-15'),
(1, '2014-02-05', '2014-08-01'),
(2, '2014-03-16', '2015-01-01')
For example in this case the n1 is overlapped in terms of date 2014-02-05 and 2014-02-06...
SELECT *
FROM tabletest LT JOIN tabletest RT ON LT.iddd=RT.iddd AND LT.datefrom<>RT.datefrom AND LT.dateto<>RT.dateto
WHERE RT.datefrom<=LT.dateto AND RT.datefrom>=LT.datefrom
Chaos isn’t a pit. Chaos is a ladder. Many who try to climb it fail and never get to try again. The fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love. Illusions. Only the ladder is real.
The climb is all there is.
Similar Messages
-
Re: Date overlap - sequence split
In refrence to my earlier post Re: Date overlap - sequence split
i would like to make changes to how the end_dt is being calculated.
original code by Frank:
WITH coverage_change AS
SELECT m_id
, strt_dt AS dt
, CASE WHEN a = 'Y' THEN 1 ELSE 0 END AS a_num
, CASE WHEN b = 'Y' THEN 1 ELSE 0 END AS b_num
, CASE WHEN c = 'Y' THEN 1 ELSE 0 END AS c_num
, CASE WHEN d = 'Y' THEN 1 ELSE 0 END AS d_num
FROM test_ovlp
UNION ALL
SELECT m_id
, end_dt AS dt
, CASE WHEN a = 'Y' THEN -1 ELSE 0 END AS a_num
, CASE WHEN b = 'Y' THEN -1 ELSE 0 END AS b_num
, CASE WHEN c = 'Y' THEN -1 ELSE 0 END AS c_num
, CASE WHEN D = 'Y' THEN -1 ELSE 0 END AS D_NUM
FROM test_ovlp
, net_coverage AS
SELECT DISTINCT
m_id
, dt
, SUM (A_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS a_net
, SUM (B_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS b_net
, SUM (C_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS c_net
, SUM (D_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS d_net
, DENSE_RANK () OVER (PARTITION BY M_ID ORDER BY dt DESC) AS from_end
, MAX (dt) OVER () AS max_dt
FROM coverage_change
, got_end_dt AS
SELECT m_id
, dt AS strt_dt
, LEAD ( dt - 1
, 1
, max_dt
) OVER ( PARTITION BY m_id
ORDER BY dt
AS end_dt
, CASE WHEN a_net > 0 THEN 'Y' ELSE 'N' END AS a
, CASE WHEN b_net > 0 THEN 'Y' ELSE 'N' END AS b
, CASE WHEN c_net > 0 THEN 'Y' ELSE 'N' END AS c
, CASE WHEN d_net > 0 THEN 'Y' ELSE 'N' END AS d
FROM net_coverage
WHERE from_end > 1
SELECT m_id, strt_dt, end_dt
, a, b, c, d
FROM got_end_dt
WHERE 'Y' IN (a, b, c, d)
ORDER BY m_id DESC
, strt_dt;Instead of calculating the end dt as 1 day less than start date of next record,
I would calculate the start date of the next record as end_dt +1 some thing like this
WITH coverage_change AS
SELECT m_id
, strt_dt AS dt
, CASE WHEN a = 'Y' THEN 1 ELSE 0 END AS a_num
, CASE WHEN b = 'Y' THEN 1 ELSE 0 END AS b_num
, CASE WHEN c = 'Y' THEN 1 ELSE 0 END AS c_num
, CASE WHEN d = 'Y' THEN 1 ELSE 0 END AS d_num
FROM test_ovlp
UNION ALL
SELECT m_id
, end_dt AS dt
, CASE WHEN a = 'Y' THEN -1 ELSE 0 END AS a_num
, CASE WHEN b = 'Y' THEN -1 ELSE 0 END AS b_num
, CASE WHEN c = 'Y' THEN -1 ELSE 0 END AS c_num
, CASE WHEN D = 'Y' THEN -1 ELSE 0 END AS D_NUM
FROM test_ovlp
, net_coverage AS
SELECT DISTINCT
m_id
, dt
, SUM (A_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS a_net
, SUM (B_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS b_net
, SUM (C_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS c_net
, SUM (D_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS d_net
, DENSE_RANK () OVER (PARTITION BY M_ID ORDER BY dt DESC) AS from_end
, MAX (dt) OVER () AS max_dt
FROM coverage_change
, got_end_dt AS
SELECT m_id
,case when row_number() over (partition by m_id order by dt asc) =1 then dt else lead ( dt + 1,1,max_dt ) OVER ( PARTITION BY m_id ORDER BY dt ) end as new_start_dt --new way of calculating start_dt
, case when row_number() over (partition by m_id order by dt asc) =1 then LEAD ( dt , 1 , max_dt ) OVER ( PARTITION BY m_id order by dt ) else dt end as new_end_dt,
, CASE WHEN a_net > 0 THEN 'Y' ELSE 'N' END AS a
, CASE WHEN b_net > 0 THEN 'Y' ELSE 'N' END AS b
, CASE WHEN c_net > 0 THEN 'Y' ELSE 'N' END AS c
, CASE WHEN d_net > 0 THEN 'Y' ELSE 'N' END AS d
FROM net_coverage
WHERE from_end > 1
SELECT m_id, new_start_dt, new_end_dt
, a, b, c, d
FROM got_end_dt
WHERE 'Y' IN (a, b, c, d)
ORDER BY m_id DESC
, strt_dt;but its not giving me correct value for start_dt for last record as i am using this lead ( dt + 1,1,max_dt ) in the start_dt calculation.
is there any alternate way to do thisHi,
user12997203 wrote:
In refrence to my earlier post Re: Date overlap - sequence split
i would like to make changes to how the end_dt is being calculated.Do you want to use the same sample data as the previous thread?
... Instead of calculating the end dt as 1 day less than start date of next record,Always post the output you want from the sample data.
I would calculate the start date of the next record as end_dt +1 some thing like thisDo you want start_date derved from the next (that is, later) row, or should it be derived from the previous (that is, earlier) row, when there is one?
WITH coverage_change AS
SELECT m_id
, strt_dt AS dt
, CASE WHEN a = 'Y' THEN 1 ELSE 0 END AS a_num
, CASE WHEN b = 'Y' THEN 1 ELSE 0 END AS b_num
, CASE WHEN c = 'Y' THEN 1 ELSE 0 END AS c_num
, CASE WHEN d = 'Y' THEN 1 ELSE 0 END AS d_num
FROM test_ovlp
UNION ALL
SELECT m_id
, end_dt AS dt
, CASE WHEN a = 'Y' THEN -1 ELSE 0 END AS a_num
, CASE WHEN b = 'Y' THEN -1 ELSE 0 END AS b_num
, CASE WHEN c = 'Y' THEN -1 ELSE 0 END AS c_num
, CASE WHEN D = 'Y' THEN -1 ELSE 0 END AS D_NUM
FROM test_ovlp
, net_coverage AS
SELECT DISTINCT
m_id
, dt
, SUM (A_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS a_net
, SUM (B_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS b_net
, SUM (C_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS c_net
, SUM (D_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS d_net
, DENSE_RANK () OVER (PARTITION BY M_ID ORDER BY dt DESC) AS from_end
, MAX (dt) OVER () AS max_dt
FROM coverage_change
, got_end_dt AS
SELECT m_id
,case when row_number() over (partition by m_id order by dt asc) =1 then dt else lead ( dt + 1,1,max_dt ) OVER ( PARTITION BY m_id ORDER BY dt ) end as new_start_dt --new way of calculating start_dt
, case when row_number() over (partition by m_id order by dt asc) =1 then LEAD ( dt , 1 , max_dt ) OVER ( PARTITION BY m_id order by dt ) else dt end as new_end_dt, You don't want a comma at the end of the line above, since the line below starts with a comma.
, CASE WHEN a_net > 0 THEN 'Y' ELSE 'N' END AS a
, CASE WHEN b_net > 0 THEN 'Y' ELSE 'N' END AS b
, CASE WHEN c_net > 0 THEN 'Y' ELSE 'N' END AS c
, CASE WHEN d_net > 0 THEN 'Y' ELSE 'N' END AS d
FROM net_coverage
WHERE from_end > 1
SELECT m_id, new_start_dt, new_end_dt
, a, b, c, d
FROM got_end_dt
WHERE 'Y' IN (a, b, c, d)
ORDER BY m_id DESC
, strt_dt;There's no column called strt_dt in got_end_dt. Did you mean new_start_dt?
but its not giving me correct value for start_dt for last record as i am using this lead ( dt + 1,1,max_dt ) in the start_dt calculation.
is there any alternate way to do thisIf you fix the 2 errors mentioned above, the output (using the sample data from Feb. 21) is:
M_ID NEW_START_D NEW_END_DT A B C D
BBBB 01-Sep-1995 01-Sep-1996 Y N N N
BBBB 01-Jan-2000 01-Sep-1996 Y Y N N
BBBB 30-Sep-2000 01-Jun-2000 N N Y N
AAAA 01-Jan-1968 01-Jan-1988 Y Y N N
AAAA 02-Jan-1997 01-Jan-1988 Y Y Y N
AAAA 30-Sep-2000 01-Jan-1997 N Y N NIs that what you want? If not, post the correct results. -
Error "User Expiry Date Overlaps" while login into system
Dear Consultants,
A strange problem started occurring in our System.When we are trying to
login in SAP system from any user apart from SAP*, after giving user name
and password it gives error:- "user expiry date overlaps".
I want to mention here our both licenses NetWeaver_ORA & Maintenance_ORAare still valid. and we are also able to login only from SAP* login
System - SAP ECC with EHP5
O.S - Linux RHEL 5.4 X86_64
Kernel - 720
Regards
Gagan sharma
Basis ConsultantSystem Time and Server Time is Exactly same
System time 21.02.2012 19:32:01 INDIA
Server Time Tue Feb 21 19:32:29 IST 2012
I also want to mention here this problem started occurring immediately without doing any change on System or Server Side
Regards
Gagan sharma -
Need help! Can't validate date overlaps for a tabular column
Hello all,
The validation I created to validate whether new or updates rows does not overlap with any records in the table isn't working.
The columns are StartDt and EndDt
Validation Type: NOT EXISTS
Validation expresion:
select 1
from sample S
WHERE S.STARTDT BETWEEN :STARTDT AND :ENDDT
OR(S.ENDDT BETWEEN :STARTDT AND :ENDDT)
or (S.STARTDT <= :STARTDT and S.ENDDT >= :ENDDT)
or (:STARTDT <= S.STARTDT and :ENDDT >= S.ENDDT)
Error Message:
Times overlap
When Buttons pressed
-Select Button-
The validation works if a new row or updated row overlaps any existing start and end date records but it doesn't work if I update startdate and end date rows that doesn't overlap existing date times
Example:
TABLE DISPLAYS THE FOLLOWING RECORDS
NAME START DATE END DATE
TEST 1/1/2012 12/31/2012
If I update the rows to the following values, I receive an error message (although those values don't overlap any records in the table)
NAME START DATE END DATE
TEST 6/1/2012 10/30/2012
Any ideas? Do I need to change my code?
Click the link to view the answer to this question. Need help! Can't validate date overlaps for a tabular column
Message was edited by: CharlieMackLogic for date range overlap testing only requires two conditions in the WHERE clause:
ORACLE-BASE - Overlapping Date Ranges
WHERE S.STARTDT <= :ENDDT AND S.ENDDT >= :STARTDT -- TRUE for ranges that overlap
It looks a little odd, but, if you scribble out a 'logic table', it makes sense.
Condition
A.start <= B.end
A.end >= B.start
A__A B--B
true
false
A__B=A--B
true
true
A__B==B__A
true
true
B--A==B__A
true
true
B--B A__A
false
true
MK -
How to check date overlapping?
Hi,
What is the easiest/simplest way to check date overlapping?
I have date_start1, date_end1, date_start2 and date_end2, and I'd like to know if they're overlapping or not.
I searched for FM OVERLAP, but so far couldn't find one, which would help.
I've found FM TB_TIME_INTERVAL_OVERLAP, which looked promising, however I couldn't make it work, maybe I used a wrong calculation method /I tried several/.
Any idea?
Thanks in advance,
PeterHi All,
You can use the FM to validate the date overlap when from date and to date in which the date ranges have been given.
<i> CALL FUNCTION <b>'GM_VALIDATE_DATE_RANGE'</b>
EXPORTING
i_from_date = sy-datum
i_to_date = c_enddt "'99991231'
TABLES
t_daterange = p_dates
EXCEPTIONS
ranges_overlap = 1
range_has_holes = 2
continuous_but_excessive = 3
OTHERS = 4
erro_message = 99.
CASE sy-subrc.
WHEN '0'.
WHEN '1'.
MESSAGE e004(z_common) DISPLAY LIKE 'E'
WITH 'Date range should not overlap with Existing One'(003).
WHEN '2'.
MESSAGE e004(z_common) DISPLAY LIKE 'E'
WITH 'Date range should not overlap with Existing One'(003).
ENDCASE.</i>
<b>OR</b>
Only for date ranges validation no matter whatever the date ranges are given.
you can use the Z function module from the above one mentioned.
<b><i>FUNCTION zgm_validate_date_range.
""Local Interface:
*" IMPORTING
*" REFERENCE(I_FROM_DATE) TYPE DATS OPTIONAL
*" REFERENCE(I_TO_DATE) TYPE DATS OPTIONAL
*" TABLES
*" T_DATERANGE STRUCTURE GMDATERANGE
*" EXCEPTIONS
*" RANGES_OVERLAP
*" RANGE_HAS_HOLES
*" CONTINUOUS_BUT_EXCESSIVE
DATA: i TYPE i,
l_next_date LIKE sy-datum,
l_first_date LIKE sy-datum,
l_last_date LIKE sy-datum,
no_days TYPE tfmatage,
cnt_next TYPE i,
w_daterange TYPE gmdaterange.
DESCRIBE TABLE t_daterange LINES i.
IF i > 1.
SORT t_daterange BY from_date.
First determine if the slices are continuous and have
no gaps.
LOOP AT t_daterange.
cnt_next = sy-tabix + 1.
IF sy-tabix > 1. " not first record
IF t_daterange-from_date <= l_next_date.
RAISE ranges_overlap.
ENDIF.
IF t_daterange-to_date <= l_next_date.
RAISE range_has_holes.
ENDIF.
ELSE.
save first date
MOVE t_daterange-from_date TO l_first_date.
ENDIF.
update end of range
MOVE t_daterange-to_date TO : l_last_date,
l_next_date.
ENDLOOP.
ENDIF.
ENDFUNCTION.</i></b>
Thanks
Ramesh Babu N -
Hi Everyone,
Can you please help me solve this issue? I have dates overlapping and with gaps. I shouldn't have any overlaps, so I need to split them as below.
Here is my test data.
create table test_dates (
prov_id varchar2(20 byte),
start_date date,
end_date date,
attribute_value varchar2(10 byte)
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-01-01', date '2010-01-31', '1', 'A');
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-02-01', date '2010-02-28', '1', 'B');
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-04-01', date '2010-04-30', '1', 'C');
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-04-15', date '2010-05-31', '1', 'D');
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-07-01', date '2010-08-31', '1', 'E');
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-07-01', date '2010-07-31', '1', 'F');
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-08-15', date '2010-08-01', '1', 'G');
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-09-01', date '2010-12-31', '1', 'H');
commit;
Expected Results:
ID
START
END
1
1/1/2010
1/31/2010
1
2/1/2010
2/28/2010
1
4/1/2010
4/14/2010
1
4/15/2010
4/30/2010
1
5/1/2010
5/31/2010
1
7/1/2010
7/31/2010
1
8/1/2010
8/31/2010
1
9/1/2010
12/31/2010Hi,
Depending on your requirements:
WITH change_points AS
SELECT prov_id
, change_date
, change_type
, SUM (change_type) OVER ( PARTITION BY prov_id
ORDER BY change_date
) AS active_cnt
, LEAD (change_date) OVER ( PARTITION BY prov_id
ORDER BY change_date
) AS next_change_date
, LEAD (change_type) OVER ( PARTITION BY prov_id
ORDER BY change_date
) AS next_change_type
FROM test_dates
UNPIVOT ( change_date
FOR change_type IN ( start_date AS 1
, end_date AS -1
SELECT prov_id
, change_date + CASE
WHEN change_type = 1
THEN 0
ELSE 1
END AS start_date
, next_change_date - CASE
WHEN next_change_type = -1
THEN 0
ELSE 1
END AS end_date
FROM change_points
WHERE active_cnt > 0
AND change_date < next_change_date
ORDER BY prov_id
, start_date
Thanks for posting the sample data; that's helpful.
It also very helpful to explain how you get the results you want from the given data. For example, what role does prov_id play in this problem? (It's hard to guess when every row in the sample data has the same value for prov_id.) Also, sometimes, the start_dates or end_dates in the output are not exactly the dates in the table; sometimes they are 1 day earlier or later. How do you decide which?
In the sample data, start_date can be later than end _date, for example:
insert into test_dates(start_date, end_date, prov_id, attribute_value) values (date '2010-08-15', date '2010-08-01', '1', 'G');
Was that a mistake? -
How do I identify records in table where dates overlap?
Hi
In a table I can have multiple records per Code. But if you look at the Start and End dates of the last two records they overlap.
Unique ID Code Start Date End Date
1 143 28-MAY-02 16-OCT-02
2 143 17-OCT-02 22-NOV-02
3 143 13-NOV-02 12-MAR-03
I want to be able to identify these and then change the values to be
Unique ID Code Start Date End Date
1 143 28-MAY-02 16-OCT-02
2 143 17-OCT-02 12-NOV-02
3 143 13-NOV-02 12-MAR-03
i.e. set the End Date of the 2nd record to be a day less than the start date of the 3rd record.
Can anyone please help with how I can do this?
Thanks
GBYou have to make the ordering unique, so I added the column end_date to the ordering.
And the solution prevented was buggy, so I replaced it with a new SQL statement:
SQL> create table test_table
2 as
3 select 1 uqid, 143 code, date '2002-05-28' start_date, date '2002-10-16' end_date from dual union all
4 select 2, 143, date '2002-10-17', date '2002-11-22' from dual union all
5 select 3, 143, date '2002-11-13', date '2003-03-12' from dual union all
6 select 1, 100, date '2007-02-01', date '2007-02-14' from dual union all
7 select 2, 100, date '2007-02-15', date '2007-02-15' from dual union all
8 select 3, 100, date '2007-02-15', date '2007-05-05' from dual
9 /
Tabel is aangemaakt.
SQL> select uqid
2 , code
3 , start_date
4 , end_date
5 , next_date -1 as replacement_date
6 from ( select uqid
7 , code
8 , start_date
9 , end_date
10 , LAG(start_date) over (partition by code order by start_date desc) as next_date
11 from test_table
12 )
13 order by code
14 , start_date
15 /
UQID CODE START_DATE END_DATE REPLACEMENT_DATE
1 100 01-02-2007 00:00:00 14-02-2007 00:00:00 14-02-2007 00:00:00
2 100 15-02-2007 00:00:00 15-02-2007 00:00:00
3 100 15-02-2007 00:00:00 05-05-2007 00:00:00 14-02-2007 00:00:00
1 143 28-05-2002 00:00:00 16-10-2002 00:00:00 16-10-2002 00:00:00
2 143 17-10-2002 00:00:00 22-11-2002 00:00:00 12-11-2002 00:00:00
3 143 13-11-2002 00:00:00 12-03-2003 00:00:00
6 rijen zijn geselecteerd.
SQL> select uqid
2 , code
3 , start_date
4 , greatest
5 ( least
6 ( lead(start_date,1,end_date+1) over (partition by code order by start_date, end_date) - 1
7 , end_date
8 )
9 , start_date
10 ) replacement_date
11 from test_table
12 order by code
13 , start_date
14 , end_date
15 /
UQID CODE START_DATE REPLACEMENT_DATE
1 100 01-02-2007 00:00:00 14-02-2007 00:00:00
2 100 15-02-2007 00:00:00 15-02-2007 00:00:00
3 100 15-02-2007 00:00:00 05-05-2007 00:00:00
1 143 28-05-2002 00:00:00 16-10-2002 00:00:00
2 143 17-10-2002 00:00:00 12-11-2002 00:00:00
3 143 13-11-2002 00:00:00 12-03-2003 00:00:00
6 rijen zijn geselecteerd.Regards,
Rob. -
Restrict Insert Dates Overlapping
Hello,
I have the following records in my table
Code_Id Item_ID Cat_Id Store_Start_Date Store_End_Date
001 IT001 CAT002 01-Jan-2005 01-Dec-2011I would like to have a trigger or function which would restrict user to insert or update in the table if dates (fully or partially) are existing for the same code_id,item_id and cat_id.
How can I do this?Lots of data integrity questions this weekend :-)
Oracle should start building the assertion feature. For with this feature your question can easily be answered by creating following assertion:
create or replace assertion no_overlapping_rows as
check(
not exists
(select 'two overlapping rows'
from your_table t1
,your_table t2
where t1.code_id = t2.code_id
and t1.item_id = t2.item_id
and t1.cat_id = t2.cat_id
and t1.start_date <> t2.start_date
and (t1.start_date between t2.start_date and t2.end_date or
t2.start_date between t1.start_date and t1.end_date))
How can I do this?Two options:
1) create triggers for this (complex but doable).
2) use the infamous MV-trick for this (see for instance here: http://technology.amis.nl/blog/475/introducing-materialized-views-as-mechanism-for-business-rule-implementation-complex-declarative-constraints -
my source will be like this
ID START DT END DT A B C D
AAAA 01/01/1968 01/01/1997 Y N N N
AAAA 01/01/1968 01/01/1999 N Y N N
AAAA 01/01/1988 01/01/1997 N N Y N
and i need break the sequence as below
ID START DT END DT A B C D
AAAA 01/01/1968 01/01/1988 Y Y N N
AAAA 01/01/1988 01/01/1997 Y Y Y N
AAAA 01/01/1997 01/01/1999 N Y N N
i am with analytical function lag but it is giving one line .
can any one help me how to code this logicHi,
user12997203 wrote:
... in the result set i really dont need a record if it is all N's Okay, I understand this much
and the start date of the next record if it has a gap in the dates should be same.You lost me. If we just get rid of the output rows with all 'N's, then we get these results:
expected output:
M_ID STRT_DT END_DT A B C D
BBBB 01-SEP-95 00:00:00 31-AUG-96 00:00:00 Y N N N
BBBB 01-SEP-96 00:00:00 31-DEC-99 00:00:00 Y Y N N
BBBB 01-JUN-00 00:00:00 30-SEP-00 00:00:00 N N Y N
AAAA 01-JAN-68 00:00:00 31-DEC-87 00:00:00 Y Y N N
AAAA 01-JAN-88 00:00:00 31-DEC-96 00:00:00 Y Y Y N
AAAA 01-JAN-97 00:00:00 30-SEP-00 00:00:00 N Y N N
The only complication is that we have to remove the rows with all 'N's after end_dt is computed, because end_dt depends on the dt from the row with all 'N's.
Here's one way to do that:
WITH coverage_change AS
SELECT m_id
, strt_dt AS dt
, CASE WHEN a = 'Y' THEN 1 ELSE 0 END AS a_num
, CASE WHEN b = 'Y' THEN 1 ELSE 0 END AS b_num
, CASE WHEN c = 'Y' THEN 1 ELSE 0 END AS c_num
, CASE WHEN d = 'Y' THEN 1 ELSE 0 END AS d_num
FROM test_ovlp
UNION ALL
SELECT m_id
, end_dt AS dt
, CASE WHEN a = 'Y' THEN -1 ELSE 0 END AS a_num
, CASE WHEN b = 'Y' THEN -1 ELSE 0 END AS b_num
, CASE WHEN c = 'Y' THEN -1 ELSE 0 END AS c_num
, CASE WHEN D = 'Y' THEN -1 ELSE 0 END AS D_NUM
FROM test_ovlp
, net_coverage AS
SELECT DISTINCT
m_id
, dt
, SUM (A_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS a_net
, SUM (B_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS b_net
, SUM (C_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS c_net
, SUM (D_NUM) OVER (PARTITION BY M_ID ORDER BY DT) AS d_net
, DENSE_RANK () OVER (PARTITION BY M_ID ORDER BY dt DESC) AS from_end
, MAX (dt) OVER () AS max_dt
FROM coverage_change
, got_end_dt AS
SELECT m_id
, dt AS strt_dt
, LEAD ( dt - 1
, 1
, max_dt
) OVER ( PARTITION BY m_id
ORDER BY dt
AS end_dt
, CASE WHEN a_net > 0 THEN 'Y' ELSE 'N' END AS a
, CASE WHEN b_net > 0 THEN 'Y' ELSE 'N' END AS b
, CASE WHEN c_net > 0 THEN 'Y' ELSE 'N' END AS c
, CASE WHEN d_net > 0 THEN 'Y' ELSE 'N' END AS d
FROM net_coverage
WHERE from_end > 1
SELECT m_id, strt_dt, end_dt
, a, b, c, d
FROM got_end_dt
WHERE 'Y' IN (a, b, c, d)
ORDER BY m_id DESC
, strt_dt;The first 2 sub-queries, coverage_change and net_coverage, are exactly the same as in my last message.
What used to be the main query (except for the ORDER BY clause) is now the sub-query called got_end_dt.
The new main query just excludes the all-'N' rows, and sorts.
If this is really what you need to do, then the query can probably be simplified a little. I put some tricky code into net_coverage to avoid another sub-query, but now, since we need another sub-query anyway (to remove the all-'N' rows) there might be a better way. -
Create table with overlapping parallel dates in individual columns
I am trying to combine data from two different tables into a single table.
The data in table 1 contains unit locations of patients within a hospital where each record represents one location. Patients can be transferred many times between different beds resulting in many records for a single visit.
The data in table 2 contains operating room activity of the patient in the hospital where each record represents either the OR of the recovery room stay. A patient may have multiple operations in one visit.
I would like to join/merge/mashup the data into a single table that has the data parallel to each other. That is, the dates for the unit activity on one side of the table and the OR activity on the other. The difficulty is that the two sets of in/out dates overlap. I would like the final table to split the original records into new records when the overlaps do not coincide.
Example:
Original Events in two records (one per table)
> Unit Event A - from 2pm to 6pm
> OR Event B - from 4pm to 5pm
Results in 3 records (in final table)
> Event 1 - Unit from 2pm to 4pm, OR dates null
> Event 2 - Unit from 4pm to 5pm, OR from 4pm to 5pm
> Event 3 - Unit from 5pm to 6pm, OR dates null
Of course the overlapping may be more complex that the above example, and adding in and out code to indicate "phantom" transfers will be needed as well.
In the code below, the first OR visit occurs during the first unit record.
Jason
Oracle 10g
[code]
create table delme_Unit_dates
( id varchar2(20)
, unit_rcd_id varchar2(20)
, Unit_desc varchar2(20)
, Unit_in_code char(1)
, Unit_in_dttm date
, Unit_out_dttm date
, Unit_out_code char(1));
create table delme_or_dates
( id varchar2(20)
, OR_rcd_id varchar2(20)
, OR_desc varchar2(20)
, OR_in_code char(1)
, OR_in_dttm date
, OR_out_dttm date
, OR_out_code char(1));
create table delme_all_dates
( id varchar2(20)
, Unit_OR_id varchar2(40)
, Unit_rcd_id varchar2(20)
, Unit_desc varchar2(20)
, Unit_in_code char(1)
, Unit_in_dttm date
, Unit_out_dttm date
, Unit_out_code char(1)
, OR_rcd_id varchar2(20)
, OR_Desc varchar2(20)
, OR_in_code char(1)
, OR_in_dttm date
, OR_out_dttm date
, OR_out_code char(1));
insert into delme_unit_dates values ('123456','U1111','Unit A','A',to_date('2013-04-29 5:02:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-09 1:06:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),'B');
insert into delme_unit_dates values ('123456','U1112','Unit A','B',to_date('2013-05-09 1:06:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-09 4:53:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),'B');
insert into delme_unit_dates values ('123456','U1113','Unit A','B',to_date('2013-05-09 4:53:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-10 10:52:00 PM', 'yyyy-mm-dd hh:mi:ss am'),'T');
insert into delme_unit_dates values ('123456','U1114','Unit D','T',to_date('2013-05-10 10:52:00 PM', 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-11 11:30:00 AM', 'yyyy-mm-dd hh:mi:ss am'),'B');
insert into delme_unit_dates values ('123456','U1115','Unit D','B',to_date('2013-05-11 11:30:00 AM', 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-12 4:00:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),'B');
insert into delme_unit_dates values ('123456','U1116','Unit D','B',to_date('2013-05-12 4:00:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-16 2:14:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),'T');
insert into delme_unit_dates values ('123456','U1117','Unit Z','T',to_date('2013-05-16 2:14:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-17 2:26:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),'B');
insert into delme_unit_dates values ('123456','U1118','Unit Z','B',to_date('2013-05-17 2:26:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-20 11:30:00 AM', 'yyyy-mm-dd hh:mi:ss am'),'D');
insert into delme_or_dates values ('123456','OR2221','OR 1','O',to_date('2013-05-09 7:35:00 AM' , 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-09 10:56:00 AM', 'yyyy-mm-dd hh:mi:ss am'),'R');
insert into delme_or_dates values ('123456','OR2222','RR 5','R',to_date('2013-05-09 10:56:00 AM', 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-09 3:20:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),'U');
insert into delme_or_dates values ('123456','OR3331','OR 2','O',to_date('2013-05-16 7:59:00 PM' , 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-16 10:43:00 PM', 'yyyy-mm-dd hh:mi:ss am'),'R');
insert into delme_or_dates values ('123456','OR3332','RR 8','R',to_date('2013-05-16 10:43:00 PM', 'yyyy-mm-dd hh:mi:ss am'),to_date('2013-05-17 11:20:00 PM', 'yyyy-mm-dd hh:mi:ss am'),'U');
commit;
-- this is nowhere near to what is needed
select
U.*
, o.*
from
delme_Unit_dates U
, delme_OR_dates O
where
U.id = o.id
and U.UNIT_IN_DTTM <= O.OR_IN_DTTM
and U.UNIT_OUT_DTTM >= O.OR_IN_DTTM
order by U.UNIT_IN_DTTM, O.OR_IN_DTTM
[/code]
Message was edited by: Jason_S (Changed one date from '2013-05-16 3:20:00 PM' to '2013-05-09 3:20:00 PM')I edited one of the dates in the original post.
Both the inpatient unit and OR events are contiguous for a given patient (no overlaps and no gaps -- after data is cleaned) .
I have no problem with a view instead of a table, and would probably prefer a view.
There are about 3 million records in the inpatient unit table and 0.5 million in the OR table.
Below is how I would like the final table (assuming I correctly split the records). I've used X's to represent the phantom movements. It seems that one should never have a phantom X in both the UNIT_IN_CODE and the UNIT_OUT_CODE (same for out codes).
FYI, The B's mean transfer within a unit (change room/ed), the T's transfer between units, O's enter OR, R's enter recovery room.
Also, the may be a future need to add an additional set of parallel dates (attending physician service)!
ID
UNIT_OR_ID
UNIT_RCD_ID
UNIT_DESC
UNIT_IN_CODE
UNIT_IN_DTTM
UNIT_OUT_DTTM
UNIT_OUT_CODE
OR_RCD_ID
OR_DESC
OR_IN_CODE
OR_IN_DTTM
OR_OUT_DTTM
OR_OUT_CODE
123456
U1111-
U1111
Unit A
A
04/29/2013 17:02
05/09/2013 7:35
X
123456
U1111-OR2221
U1111
Unit A
X
05/09/2013 7:35
05/09/2013 10:56
X
OR2221
OR 1
O
05/09/2013 7:35
05/09/2013 10:56
R
123456
U1111-OR2222
U1111
Unit A
X
05/09/2013 10:56
05/09/2013 13:06
B
OR2222
RR 5
R
05/09/2013 10:56
05/09/2013 13:06
X
123456
U1112-OR2222
U1112
Unit A
B
05/09/2013 13:06
05/09/2013 15:20
X
OR2222
RR 5
X
05/09/2013 13:06
05/09/2013 15:20
U
123456
U1112-
U1112
Unit A
X
05/09/2013 15:20
05/09/2013 16:53
B
123456
U1113-
U1113
Unit A
B
05/09/2013 16:53
05/10/2013 22:52
T
123456
U1114-
U1114
Unit D
T
05/10/2013 22:52
05/11/2013 11:30
B
123456
U1115-
U1115
Unit D
B
05/11/2013 11:30
05/12/2013 16:00
B
123456
U1116-
U1116
Unit D
B
05/12/2013 16:00
05/16/2013 14:14
T
123456
U1117-
U1117
Unit Z
T
05/16/2013 14:14
05/16/2013 19:59
X
123456
U1117-OR3331
U1117
Unit Z
X
05/16/2013 19:59
05/16/2013 22:43
X
OR3331
OR 2
O
05/16/2013 19:59
05/16/2013 22:43
R
123456
U1117-OR3332
U1117
Unit Z
X
05/16/2013 22:43
05/17/2013 14:26
B
OR3332
RR 8
R
05/16/2013 22:43
05/17/2013 14:26
X
123456
U1118-OR3332
U1118
Unit Z
B
05/17/2013 14:26
05/17/2013 23:20
B
OR3332
RR 8
X
05/17/2013 14:26
05/17/2013 23:20
U
123456
U1118-
U1118
Unit Z
B
05/17/2013 23:20
05/20/2013 11:30
D
Jason -
Transparency fill in line graph data points does not copy over to Pages
I have created some line graphs in Numbers, and they look beautiful. Since some of my data overlap and I want users to be able to easily see where all data is on the graph, I have made the data points transparent on the foremost line. This allows the other line (which data points are filled in with another color) visible "through" the foremost line.
However, when I attempt to copy the graphs into Pages, the data points of the foremost line are no longer transparent - they are filled with white. Obviously, this defeats the entire purpose of using a transparency fill!
What can I do to make this work?
Thank you,
G. PasarescuHi Yvan,
Thank you for the tip. Unfortunately, I need to embed several of these charts into the Pages document, and cannot use Numbers instead of Pages for the document.
Interestingly, if I copy the chart from Numbers and paste it into some graphics programs (like Pixen and Pixelator), the transparency is preserved. However, pasting the same copy into other graphics programs (such as Seashore or Photoshop) somehow flattens the image, removing the transparency, and I'm back to square one.
Using a graphics program as the bridge between Numbers and Pages reduces the quality of the chart - that's why I'd like to try to make this work in Numbers / Pages.
Thanks,
Geoff -
Fastest way to write raw data to hard drive (PhysicalDrive) on Windows 7
My company is developing a "fancy" USB Mass Storage Device running under Windows 7. The Mass Storage Client Driver that handles the reading and writing to the actual storage media on the client side is being written in C++.
The problem we are having is very, very slow write speeds. About 30 times slower than expected. We are using calls to WriteFile() to write blocks of data to the storage media (specifically the physical drive 'PhysicalDrive2') as they are received
from the Host device. I have read in many other forums that people have experience very slow write speeds using WriteFile() especially on Windows 7. So I am trying to figure out if I am using the best method and function calls for this particular
task.
Below are some blocks of code. One for Disk_GetHandle() which gets a handle to the physical drive and is called only once. One for LockVolume() function that gets called one time by the program during initialization. The other block of
code is WriteSector() which is used to write the actual data to the physical drive when its received by the USB Client controller driver. I am hoping that someone can shed some light on what I might be doing wrong or provided suggestions on a better
way to implement this.
UINT WriteSector(HANDLE hWriteDisk, PBYTE Buf, ULONG Lba, ULONG Blocks)
DWORD bytesWritten;
LPTSTR errMsg = "";
//setup overlapped structure to tell WriteFile function where to write the data
OVERLAPPED osWrite;
memset(&osWrite, 0, sizeof(osWrite));
osWrite.Offset = (Lba * SIZE_OF_BLOCK);
osWrite.hEvent = 0;
//write the data
if (!WriteFile(hWriteDisk, Buf, (Blocks * SIZE_OF_BLOCK), &bytesWritten, &osWrite))
DWORD Errorcode = GetLastError();
if (Errorcode == ERROR_IO_PENDING)
WaitForSingleObject(osWrite.hEvent, INFINITE);
else
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errMsg, 255, NULL);
printf("WriteSector() - WriteFile failed (%s)\n", errMsg);
goto exit;
if (bytesWritten != (Blocks * SIZE_OF_BLOCK))
printf("WriteSector() - Bytes written did not equal the number of bytes to be written\n");
return 0;
else
return Blocks;
HANDLE Disk_LockVolume(LPCWSTR _dsk)
HANDLE hVol;
LPWSTR errMsg;
DWORD status;
bool success = false;
//now try to get a handle to the specified volume so we can write to it
hVol = CreateFile(_dsk, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
//check to see if we were able to obtain a handle to the volume
if( hVol == INVALID_HANDLE_VALUE )
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errMsg, 255, NULL);
printf("Disk_LockVolume() - CreateFile failed (%s)\n", errMsg);
goto exit;
// now lock volume
if (!DeviceIoControl(hVol, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &status, NULL))
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errMsg, 255, NULL);
printf("Disk_LockVolume() - Error attempting to lock device! (%s)\n", errMsg);
goto exit;
//dismount the device
if (!DeviceIoControl(hVol, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &status, NULL))
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errMsg, 255, NULL);
printf("Disk_LockVolume() - Error attempting to dismount volume. (%s)\n", errMsg);
goto exit;
exit:
return hVol;
HANDLE Disk_GetHandle(UINT Lun)
HANDLE hVol;
LPTSTR errMsg = "";
DWORD status;
bool success = false;
//now try to get a handle to the specified volume so we can write to it
hVol = CreateFile(MassStorageDisk[Lun].PhysicalDisk, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, 0);
//check to see if we were able to obtain a handle to the volume
if( hVol == INVALID_HANDLE_VALUE )
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errMsg, 255, NULL);
printf("Disk_WriteData() - CreateFile failed (%s)\n", errMsg);
return hVol;Good for you for fixing the bug. On the second go-round, I noticed another one, though. You are not setting the hEvent handle on the OVERLAPPED structure. If you ever do get an ERROR_IO_PENDING, it would probably be bad inside WriteFile,
but even if that returned, you would get a problem when calling WaitForSingleObject.
It helps that we know the actual WriteFile call is what is taking the time. From your description, though, it's not clear what the precise issue is. You are comparing write speeds of your SSD vs. a regular USB flash drive. Are you also
comparing your program to that of another program? If the comparison is just between SSD and the existing USB drive, why do you not believe you have established that IO on the SSD is slow? Your last sentence is confusing: you first say that the IO on
the USB drive was as expected and IO on the SSD was slower, then say that a file write unto the USB drive took 2.5 mins and copying it to the SSD took 2.5 seconds. I assume these times were reversed.
BTW, personally for that kind of benchmarking, I would prefer non-buffered, synchronous IO myself.
I would also consider using
Process Monitor, for more information about what is going on with the low-level IO events. Ignore the benchmarking numbers when procmon is running, but getting a log from it will give you more visibility into what events are firing and their sequence,
what flags the IFS is seeing, etc. -
A slightly complex date question
Hello,
I have a series of date ranges, for example:
08/02/2008-08/04/2008
07/06/2007-07/10/2007
06/05/2006-06/12/2006
The user enters another set of dates:
08/01/2008-08/04/2008
I need to make sure that the range of dates they enter do not
overlap with any of the dates mentioned above. The one that the
user entered would conflict with (1) above and should return an
error.
If they enter another date like:
01/01/1999-02/15/2009
This should also return an error because this date conflicts
with ALL of the date ranges above. I would appreciate any help on
this issue.quote:
Originally posted by:
paross1
Wouldn't changing LTE and GTE to LT and GT take care of your
"problem"?
Phil
No:
I need to check for date overlaps.
08/14/2008-08/20/2008
And I enter 08/15/2008-8/17/2008, this should yield false,
because this date range has dates that overlap. If I enter
02/07/2007-02/09/2009, it should also yield false, and so should
08/13/2008-08/15/2008, and 08/17/2008-08/22/2008.
All of them are invalid dates and should not be allowed.
Maybe I am explaining the issue improperly. Basically, no
single day within the range I enter should overlap with any single
day within the existing date range. -
Master data extraction BW 7.0
In Master data extraction of 0PERSON_ATTR one record in the PSA is getting duplicated inside Error Stack as many times as we run the PSA dataload.Because of this Error mssg is displayed as Dates overlapped.
Hi,
In error stack check, which records are getting duplicated and whether the same date is avialable in both the record ( since message is overlapping dates). if it is you can check with psa and manually correct the records in error stack.
create a error DTP( you will find this option in existing DTP). and schdule this to load the corrected records from Error stack.
rgrds,
v.sen. -
One SAP BI 7 system pulling data from 2 ECC 6 systems
Hello experts,
has any one gone through the scenario of extracting data from 2 SAP ECC 6 systems in to one BI 7 system? If so, What were the challenges from the view of configuration, performance and security? I appreciate your feed back.
Thanks,
Prasanthi Bellam>
prasanthi bellam wrote:
> Hello experts,
> has any one gone through the scenario of extracting data from 2 SAP ECC 6 systems in to one BI 7 system? If so, What were the challenges from the view of configuration, performance and security? I appreciate your feed back.
>
> Thanks,
> Prasanthi Bellam
Configuration, Peformance and security wouldnot be a issue, the only issue was cleansing the data from two system.
We actually went with compounding all the objects with source system tag, which involved heavy manual activity.But before going to this, you can check out if there is master data overlap for the two systems if not then you can do away without compounding.
Maybe you are looking for
-
Business Graphics - Stacked Column - Stack with different colours
Hello Experts, In the Webdynpro application, I'm using a business graphics UI element and displaying data in stacked columns. The color of the stacks are by default assigned by the framework. But I would like to change the color of the stacks and wan
-
Okay, so since 'upgrading' to iOS 7 the photo I used to use as my background will not resize to fit the screen like it used to. It's the same photo and I have found the re-size etc stuff in the control centre but it will not allow me to change the si
-
Regarding accesing integration builder tool for java proxy generation
Hi Abapers, How can I access integration builder tool to generate java proxy via SAP XI server in my ECC 5.0? Please give me the clear idea of that. regards Subash
-
Batch rename of selected files undoes all my groups
I use groups extensively in Bridge CS3. Lately, when I batch rename files within a group, Bridge completely undones all the groups in the folder (2.5GB, total). Why is that happening? Thanks
-
Compiling JSSE source code I got NetBeans warning "Import From Forbidden Package" at every import sun.* statement. Why is import forbidden and where can I read about that prohibition with more details?