1 -how is this different from your previous question? If it's not, then simply use that answer here.
If it is different, please explain how?
2 - Why is end_dt using 2-digit years and the other dates 4-digit years?
awking00
First question - what are the date formats (I assume the fields are varchar2)?
Second question - if RCD 6 started 2014-12-12 (I assume to be December 12, 2014) and ended 15-12-12 (assumed to be December 12, 2015). why wouldn't the months active in Q3 be 4, since he/she would have been active December, 2014, October, 2015, November, 2015, and December, 2015?
Jim Horn
(Not a direct answer) I have an article out there T-SQL: Identify Bad Dates in a Time Series which is SQL Server T-SQL with a bunch of Common Table Expressions (CTE's) that analyze a time series for custom logic such as gaps, overlaps, and duplicates. This code should be very transferrable to Oracle, and you can modify the custom logic to suit your needs.
That is, a record from November of 1982 would count because that's active in Q3? Or a record for December 2037?
Or, do you mean Q3 as in the most recent period Oct-Dec based on the current date?
So, since today is Feb 3, 2016, then Q3 means Oct-Dec of 2015?
Also, in your Q2 example.
The first row shows active for 9 months. Where does that number come from? The record looks like it was active for almost 8 years.
The second row shows 12 months active. But in Q2 that person would have only been there for 9 months.
Is that a mistake in your example, or are you not looking for time "as of" a particular quarter?
awking00
I think a little more clarification is needed. Are you trying to say that, if an employee's start_dt or end_dt encompasses some time in Q3, compute the number of active months from the month of the end_dt back to the month of the start_dt ? So RCD 0 would be from December 2014 to August 2015 and RCD 6 would be from December 2014 to December 2015. The problem I see is that the difference between the two would be 8 and 12 and the count of the months the employee was active would be 9 and 13?
1)Months active is months between start_dt and end_dt
2)Right now i am just asking 2015 Q3 but this is just example so how we get Quater is
if we see for data range falling between start date and end date between 2015 Q3 pick that record
else ignore that
Example in below case date range falls between 2014-12-12 to 2015-12-12 so if i say give me anything
which falls in quarter 2015 Q3 i should pick up this record.
which do you want? or do you not want formatted text but instead want date values returned?
Sean Stuber
assuming you want dates try this...
SELECT t.*, MONTHS_BETWEEN(end_dt, start_dt) months_active
FROM yourtable t
WHERE action = 'ADL'
AND end_dt >= TO_DATE('2015-10-01', 'yyyy-mm-dd') -- Q3 start
AND start_dt <= TO_DATE('2015-12-31', 'yyyy-mm-dd') -- Q3 end
comparing the end to the start and the start to the end is intentional, not a typo
If it is different, please explain how?
2 - Why is end_dt using 2-digit years and the other dates 4-digit years?