Between Dates
Hi,
Can anyone help, I am having trouble with producing a query that looks at two dates and determines if the employee was active during certains years and months.
I have a query that outputs the employees effective start date and effective end date:
person_id effective_start_date effective_end_date
118 01-JUN-2010 31-DEC-4712
1120 01-APR-2009 01-JAN-2010
110 01-SEP-2008 31-DEC-4712
For active employees the maximum end date defaults to 31-DEC-4712.
I am trying to find out if an employee was active between Years 2007-2010 using a condition:
e.g. Querying Month = SEP-2010
effective_start_date < 01-SEP-2010 and effective_end_date >= 01-SEP-2010
How can this be acheived in the output, I would like a table that shows occurences by month as below:
person_id active_month
118 Jun-2010
118 Jul-2010
118 Aug-2010
118 Sep -2010 etc. until 2012
Can anyone help?
Thanks
I would like the results to insert a record
Can anyone help?Sure.
WITH my_data as (
SELECT 118 person_id,to_date('01-JUN-2010','DD-MON-YYYY') effective_start_date,to_date('31-DEC-4712','DD-MON-YYYY') effective_end_date FROM DUAL
UNION ALL
SELECT 1120 person_id,to_date('01-APR-2009','DD-MON-YYYY') effective_start_date,to_date('01-JAN-2010','DD-MON-YYYY')effective_end_date FROM DUAL
UNION ALL
SELECT 110 person_id,to_date('01-SEP-2008','DD-MON-YYYY') effective_start_date,to_date('31-DEC-4712','DD-MON-YYYY')effective_end_date FROM DUAL),
month_starts AS (
SELECT DISTINCT DT FROM (
SELECT LAST_DAY(to_date('01-AUG-2008','DD-MON-YYYY') + (LEVEL +1))+1 AS DT
FROM DUAL
CONNECT BY LEVEL <= to_date('01-NOV-2012','DD-MON-YYYY') - (to_date('01-AUG-2008','DD-MON-YYYY'))))
SELECT my_data.person_id,to_char(month_starts.dt,'MON-YYYY') Mt
from my_data
inner join month_starts
ON (month_starts.dt between my_data.effective_start_date and my_data.effective_end_date)
where my_data.person_id=118
order by month_starts.dt Asc;
order by month_starts.dt Asc;
PERSON_ID MT
118 JUN-2010
118 JUL-2010
118 AUG-2010
118 SEP-2010
118 OCT-2010
118 NOV-2010
118 DEC-2010
118 JAN-2011
118 FEB-2011
118 MAR-2011
118 APR-2011
118 MAY-2011
118 JUN-2011
118 JUL-2011
.... Why "until 2012" and not 4712 ;-)
-- andy
Similar Messages
-
I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
[ABCTABLE]
ABCORDER
ABCPART
ABCSERIAL
ABCDATE
[ZYXTABLE]
XYZORDER
XYZPART
XYZSERIAL
XYZDATE1
XYZDATE2Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
on this computer. There are no "Null" fields in either of the tables.
This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
[MSORDR]
MSORDER
MSPART
MSSERIAL
MSOPNDATE
11111111
4444444
55555
2/4/2015
22222222
6666666
11111
1/6/2015
33333333
6666666
11111
3/5/2015
This table has one order for every part number and every serial number.
[GLORDR]
GLORDER
GLPART
GLSERIAL
GLSTARTDATE
GLENDDATE
ABC11111
444444
55555
1/2/2015
4/4/2015
ABC22222
666666
11111
1/5/2015
4/10/2015
AAA11111
555555
22222
3/2/2015
4/10/2015
Post Query table
GLORDER
MSORDER
GLSTARTDATE
GLENDDATE
MSOPNDATE
ABC11111
11111111
1/2/2015
4/4/2015
2/4/2015
ABC22222
22222222
1/5/2015
4/10/2015
1/6/2015
ABC22222
33333333
1/5/2015
4/10/2015
3/5/2015
This is the SQL minus the between date join.
SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART); -
What is difference between data base structure and stucure in program
what is difference between data base structure and stucure declared in program level . can explain cleary if knows
Hi,
Data base structure is global decalaration you can reffer this structure in any of your developments, when ever you cahange this structure the changes automatically will get updated in all the programs.
coming to structures in program it is local to your program only, if you want to change the structure again you have to open the program and do the necessary changes.
Reward if useful.
Thanks,
Sreeram. -
Returne between dates in case when
i want to return between dates values on case when clauses on where clauses
like
and
(case
when (cc.segment3 NOT like '4%' and cc.segment3 NOT like '5%')
then (between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr'))
when (cc.segment3 like '4%' or cc.segment3 like '5%')
then (between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr'))
end) h.default_effective_date
the problem is in the = operator but i don't know haw to use this
any help??ok here is the full coad
select
DECODE(SUBSTR (CC.segment1, 1, 1), 'J', 'OFFSHORE', 'I', 'OFFSHORE','IN COUNTRY')branch_nature,
decode(cc.segment1,'A6260','Head Office','Branches') branch_type,
cc.segment1,
decode (h.currency_code,'EGP','mahly','agnaby') currency_code ,
cc.segment3,
t.description,
CASE
when h.currency_code in('EGP') then sum(l.entered_cr)
else 0
end entered_cr,--sum(l.entered_cr) entered_cr,
CASE
when h.currency_code in('EGP') then sum(l.entered_dr)
else 0
end entered_dr, --sum(l.entered_dr) entered_dr,
CASE
when h.currency_code NOT in('EGP') then sum(l.accounted_cr)
else 0
end accounted_Dr,--0 accounted_Dr,
CASE
when h.currency_code NOT in('EGP') then sum(l.accounted_dr)
else 0
end accounted_cr --0 accounted_cr
from apps.gl_je_headers h,
apps.gl_je_lines L,
apps.gl_code_combinations cc,
apps.fnd_flex_values_tl t ,
applsys.fnd_user us,
apps.gl_je_batches b
where h.status = 'P'
and us.user_id = h.Created_by
--and h.currency_code in('EGP')
and l.je_header_id = h.je_header_id
and l.code_combination_id =cc.code_combination_id
and cc.segment3 = t.flex_value_meaning
and cc.segment3 in ('31000020','40505020')
and cc.segment1 in ('A5550','B0010')
-- and (DECODE(SUBSTR (CC.segment1, 1, 1), 'J', 'OFFSHORE', 'I', 'OFFSHORE','IN COUNTRY') =:P_branch_nature OR :P_branch_nature is NULL)
--and (decode(cc.segment1,'A6260','Head Office','Branches') = :P_BRANCH_TYPE OR :P_BRANCH_TYPE is NULL)
and t.description is not null
and t.language ='AR'
and h.je_batch_id = b.je_batch_id
and
(case
when (cc.segment3 NOT like '4%' and cc.segment3 NOT like '5%')
then (between to_date(:P_Start_date,'dd/mm/rrrr') and to_date(:P_END_date,'dd/mm/rrrr'))
when (cc.segment3 like '4%' or cc.segment3 like '5%')
then (between to_date(:P_Start_date2,'dd/mm/rrrr') and to_date(:P_END_date,'dd/mm/rrrr'))
end) h.default_effective_date
and (case
when (cc.segment3 like '4%' or cc.segment3 like '5%')
then (h.default_effective_date)
end) between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr')*/
group by cc.segment3 , t.description , cc.segment1,h.currency_code;
the part between tages need to modigied -
Difference between Data staging and Dimension Table ?
Difference between Data staging and Dimension Table ?
Data Staging:
Data extraction and transformation is done here.
Meaning that, if we have source data in flat file, we extract it and load into staging tables, we take care of nulls, we change datetime format etc.. and after such cleansing/transformation at then end, load it to Dim/Fact tables
Pros: Makes process simpler and easy and also we can keep track of data as we have data in staging
Cons: Staging tables need space hence need memory space
Dimension Table:
tables which describes/stores the attribute about specific objects
Below is star schema which has dimension storing information related to Product, Customer etc..
-Vaibhav Chaudhari -
Difference between date info object in characteristics and keyfigure
What is the difference between "date" data type in characteristic and keyfigure?
Thanks in advance.
RajHi Rajasekhar,
If date is characteristics,query can be analysed based on date and filters can also be set using this date.
If it is key figure query cannot be analysed based on date,
Based on requirements,we have to decide whether it should be chatracteristic or key figure
Regards
Prakash -
How to count the days between Date Range using OO ABAP?
hi experts,
i want to count the days between Date Range using OO ABAP for that which class and method can i use?.
Thanks,
Mahesh.Not sure I understand the requirement for it to be OO, but you could always write your own (i.e. use this):
REPORT zz_date_diff.
CLASS date_diff DEFINITION.
PUBLIC SECTION.
METHODS diff IMPORTING i_date_fm TYPE d
i_date_to TYPE d
EXPORTING e_days TYPE i.
ENDCLASS."
CLASS date_diff IMPLEMENTATION.
METHOD diff.
e_days = i_date_to - i_date_fm.
ENDMETHOD."
ENDCLASS."
DATA: g_ref TYPE REF TO date_diff,
g_days TYPE i,
g_date_fm TYPE d VALUE '20080101',
g_date_to TYPE d VALUE '20090101'.
START-OF-SELECTION.
CREATE OBJECT g_ref.
CALL METHOD g_ref->diff
EXPORTING
i_date_fm = g_date_fm
i_date_to = g_date_to
IMPORTING
e_days = g_days.
WRITE g_days. -
Customizing distance between data Points on x-Axis
Hi,
I want to draw a LineChart.
I have these Timestamps [84, 1000, 34000, 34699, 439999] who
are represanting the x-Value of DataPoints along the X-Axis.
Unfortunately the distance between 2 datapoints along the
x-Axis is always the same, that means that between the points with
x-values 84 and 1000 is the same distance along the axis as between
the points with x-values 34699 and 439999.
But the distance between points with x-values of 34699 and
439999 should be much greater than between 84 and 1000.
How can I customize the distance between data Points on a
LineChart to solve my Problem?
I really dont know right now!
Greeting,
Z."zidaninho" <[email protected]> wrote in
message
news:gls479$nkt$[email protected]..
> Hi,
>
> I want to draw a LineChart.
> I have these Timestamps [84, 1000, 34000, 34699, 439999]
who are
> represanting
> the x-Value of DataPoints along the X-Axis.
>
> Unfortunately the distance between 2 datapoints along
the x-Axis is always
> the
> same, that means that between the points with x-values
84 and 1000 is the
> same
> distance along the axis as between the points with
x-values 34699 and
> 439999.
> But the distance between points with x-values of 34699
and 439999 should
> be
> much greater than between 84 and 1000.
>
> How can I customize the distance between data Points on
a LineChart to
> solve
> my Problem?
>
> I really dont know right now!
What happens if you convert the time stamps to Dates and use
a DateAxis? -
Between Date parameter is not working.
Hi All,
This is my Dataset query. Other filters are working fine. I am getting out put when i select date range. But Its not working when i select Null Option (That time i should get all the data). but Its not working.
SELECT DISTINCT
PartnerId, [Partner Name], [Partner Site], [Organization/Country Code], [Accreditation Name], [Accreditation Status], [Accreditation Review Date],
CONVERT(varchar(90), [Accreditation End Date], 105) AS [Accreditation End Date], CONVERT(varchar(90), [Accreditation Start Date], 105) AS [Accreditation Start Date],
[Accreditation Code], [Specialization Code], Name, Inheritance, Description, Territory, Level
FROM P1_Addition_Report
where BU in (@BU) and Level In (@Level) and [Accreditation Name] in (@AccreditationName) and ([Accreditation Start Date] Between @Eligibility_StartDate and @Eligibility_Enddate) or (@Eligibility_StartDate is null and @Eligibility_Enddate is null)
Can anyone correct this query or suggest any alternatives
Thanks in AdvanceThanks for reply. Actually with the code i have pasted i am able to get output for Between date. but the problem is I have 5 Filters . when i select null. Its not considering the filters. Instead of that it is considering all data.
PFB screenshot for filter.. Please help to rectify this
See the way I wrote WHERE clause. If you write like that it will still apply the other filters even when date is NULL
where BU in (@BU) and Level In (@Level) and [Accreditation Name] in (@AccreditationName)
and ([Accreditation Start Date] >= @Eligibility_StartDate or @Eligibility_StartDate is null)
and ([Accreditation Start Date] < @Eligibility_Enddate+1 or @Eligibility_Enddate is null)
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
IIf condition between dates using mdx query
Hi,
how to check IIF condition between dates using mdx query.
I able to check single year,plese check below mdx query.I need to check members between years.
my requirement is member is belongs to between years(2007 to 2010),display "yes" else "NO";
Could you please give me exact mdx query.
From,to-2007,2010,if member belongs to 2007to 2010 then disply "yes"else "no".
how to pass two members in IIf condition.
WITH
MEMBER Measures.[test]
AS Iif([Date].[Calendar Year].currentmember
is [Date].[Calendar Year].&[2007],"no","yes")
SELECT {Measures.[test]}
on 0
,[Product].[Subcategory].[Subcategory].MEMBERS * [Date].[Calendar Year].[Calendar Year]
ON 1
FROM [Adventure Works]
induHi Sriindu,
consider the following:
WITH
MEMBER measures.[test] AS
IIF
Exists
[Date].[Calendar Year].CurrentMember
[Date].[Calendar Year].&[2007] : [Date].[Calendar Year].&[20010]
).Item(0)
IS
[Date].[Calendar Year].CurrentMember
,"yes"
,"no"
SELECT
{measures.[test]} ON 0
[Product].[Subcategory].[Subcategory].MEMBERS
[Date].[Calendar Year].[Calendar Year] ON 1
FROM [Adventure Works];
Philip, -
Validating is between date prompt
Is there a way to validate the is between date prompt in OBIEE?
The user should not be able to select a end date which is earlier than the start date.hi,
How about this?
http://shivabizint.wordpress.com/2009/04/21/date-between-validation-for-dashboard-prompt/
before doing,take a backup of your .js file
thanks,
saichand.v -
Connection between data services and BWA
Hi,
I want to make a connection between Data Services 3.2 and BWA. Since we use RFC connection in between in order to have them talk with eachother but i wonder if there is any documentation that describes the RFC connection and configuration required particularly in this scenario. I have gone through the documentation that explains RFC connection between Data Services and BW and what configuration we have to do, so i wonder if there are any functions we have to export to BWA from Data Services like we do in case of BW connection to Data Services or some specific configuration we have to do. If someone help who has done connection between Data Services and BWA can help or if somebody can provide documentaton on it.Hi,
You should ask this question over here: http://scn.sap.com/community/data-services
Regards,
H -
I have a requirement to create a prompt where there are two dates
FROM_DATE
TO_DATE
Need to put between date functionality that goes like this,
Between FROM_DATE and TO_DATE.
This is easy to implement if there is just one date column, in this case there are two date columns.
Any ideas?The wrinkle I use is to create a formula; -
case when 1=2 then 0 else 1 end
I then put a prompt on this and repoint it at the date in question as my TO condition.
hope this helps,
Robert. -
Finding days in between dates expressed in days.
Hi, i have a table having a structure similar to this:
LP1
TIME_EQ
P_DAY
LP2
17.2
0
MONDAY
16.8
0.25
TUESDAY
17.03
.5
THURSDAY
17
.75
FRIDAY
17.4
1
FRIDAY
16.9
.25
SATURDAY
17.1
.25
SATURDAY
17
.5
SUNDAY
Now, i have two variable dates D1 = October 10, 2013 (Thursday) and D2 = October 13, 2013 (Sunday).
How do i update my table such that only those rows covered between dates D1 and D2 are updated? In this case, rows where P_DAY in (Thursday, Friday, Saturday, Sunday) I will use this for my cursor, my query begins with this:
CURSOR LOAD_PROF is
SELECT LP1, TIME_EQ, P_DAY
FROM LOAD_PROFILE_TEST
WHERE P_DAY in (??? days between D1 & D2).
I hope you get my point. Thanks.Thank you sir for your response. This is the start of my query where I will use that:
DECLARE
CURSOR LOAD_PROF
IS
SELECT LOAD_PROF1,
V_TIME,
PROFILE_DAY,
DECODE(UPPER(PROFILE_DAY),
'MONDAY', 1,
'TUESDAY', 2,
'WEDNESDAY', 3,
'THURSDAY', 4,
'FRIDAY', 5,
'SATURDAY', 6,
'SUNDAY', 7,
'HOLIDAY', 8,
'H_WEEK_T', 9,
'H_WEEK_F', 10)
ORDERBY
FROM LOAD_PROFILE_TEST
WHERE SUBSTATION_CODE = :V_SUBSTATION_CODE
AND CIRCUIT_CODE = :V_CIRCUIT_CODE
AND UPPER(PROFILE_DAY) IN (SELECT UPPER(
TO_CHAR
:V_DATE + (level-1),
'fmDAY'))
FROM dual
CONNECT BY LEVEL <=
:V_DATE_IN
- :V_DATE
+ 1 )
ORDER BY ORDERBY, V_TIME;
V_PROF NUMBER;
Y_OUT1 NUMBER;
Y_OUT2 NUMBER;
Y_OUT3 NUMBER;
Y_OUT4 NUMBER;
Y_IN1 NUMBER;
Y_IN2 NUMBER;
Y_IN3 NUMBER;
Y_IN4 NUMBER;
Y_OUT NUMBER;
Y_IN NUMBER;
Y_OUT_A NUMBER;
Y_IN_A NUMBER;
Y_OUT_B NUMBER;
Y_IN_B NUMBER;
OUT_EXCL NUMBER;
IN_EXCL NUMBER;
OUT_EXCL_A NUMBER;
IN_EXCL_A NUMBER;
OUT_EXCL_B NUMBER;
IN_EXCL_B NUMBER;
UPPER_AREA NUMBER;
LOWER_AREA NUMBER;
UPPER_AREA_A NUMBER;
LOWER_AREA_A NUMBER;
UPPER_AREA_B NUMBER;
LOWER_AREA_B NUMBER;
DURATION NUMBER;
BEGIN
IF :LOAD_DIFF < > 0
THEN
FOR UE IN LOAD_PROF
LOOP
EXIT WHEN LOAD_PROF%NOTFOUND;
UPDATE LOAD_PROFILE_TEST
SET LOAD_PROF2 = LOAD_PROF1 + :LOAD_DIFF;
END LOOP;
ELSE
FOR UE IN LOAD_PROF
LOOP
EXIT WHEN LOAD_PROF%NOTFOUND;
UPDATE LOAD_PROFILE_TEST
SET LOAD_PROF2 = LOAD_PROF1;
END LOOP;
END IF;
COMMIT;
CALC_UE_AREA(:V_DATE, :V_SUBSTATION_CODE, :V_CIRCUIT_CODE);
CALC_UE_CUMUL_AREA(:V_DATE, :V_SUBSTATION_CODE, :V_CIRCUIT_CODE);
The column AREA is dependent from the column LOAD_PROF2, which I got by updating all the row in my cursor. The column CUMUL_AREA in turn, is dependent on the column AREA. After running these 2 procedures, i will now be able to compute for parameters which i need, using extrapolation method on the dates, LOAD_PROF2 & CUMUL_AREA
Anyways, I will be proceeding with this query for now. I hope you can give me a better suggestion onhow to better approach my problem. Thanks very much for your help. I will now close this thread but again, I will still wait for your suggestion. Thanks again. -
I need to know how i can find difference between date
like Joining date: 01-jan-2009 Today 10-jan-2010 result will be "1 year 10 days"
I need it in Oracle forms 6i. plz help me...Hi,
In oracle forms you can use
RESULT :=
TRUNC ((:date2 - :date1 + 1) / 365)
|| ' year and '
|| MOD (:date2 - :date1 + 1, 365)
|| ' days';
in sql you can use
SELECT TRUNC ((:date2 - :date1 + 1) / 365)
|| ' year and '
|| MOD (:date2 - :date1 + 1, 365)
|| ' days'
FROM DUAL; -
Diference between DATA: and TYPES: on internal tables
Hi people,
Can somebody help me. I wanna know whats the diference between DATA: and TYPES: on internal tables
and whitch has the best performance, here is a eg:
DATA: BEGIN OF ti_sbook occurs 0,
carrid LIKE sbook-carrid,
fldate LIKE sbook-fldate,
customid LIKE sbook-customid,
loccuram LIKE sbook-loccuram,
END OF ti_sbook.
AND
TYPES: BEGIN OF ti_sbook ,
carrid LIKE sbook-carrid,
fldate LIKE sbook-fldate,
customid LIKE sbook-customid,
loccuram LIKE sbook-loccuram,
END OF ti_sbook.
DATA: gw_sbook TYPE TABLE OF ti_sbook,
gs_sbook TYPE ti_sbook.
witch of both types is better?
thanks.Hi Marcelo,
For compatibility matters is better to create internal tables with a work area separately. So yes it's better to use types. When you work with Object Oriented coding you will need to use internal tables defined with types. Also when defining tables with types is the new way of coding, the another coding is getting obsolete defined by SAP. That's why when working in ABAP with OO (Object Oriented) code you'll have to define tables with types and not the other way.
Hope it helps.
Regards,
Gilberto Li
Maybe you are looking for
-
How to get attribute value of a node
Hi experts I have a mapped node in my view context from component controller context. This node consists of 2 value attributes inside Example: NODE1 - > Cardinality 1..1, seleciton 1..1 -- x_date - > type DATS -- x_years
-
IPhoto 6 and 8 Incompatibility
I have a few thousand photos in iPhoto 6.0.6 and will shortly buy a new Mac and get iPhoto 8. Meanwhile, my daughter has a new iMac and runs iPhoto 8. I recently sent some of my photos to her Mac so I could edit them using iPhoto 8's superior editing
-
I've been running the desktop mode of Adobe Story on two separate systems - my laptop and my desktop PC, primarily the former, on which I created two separate scripts. This evening, I started a new project on the desktop machine, and put a couple of
-
I have a non functioning "Apple Performa Display", Model: M9102LL/D. It appears that the power switch is defective since I can get pilot light and raster by holding the switch in but when I let go, the monitor shuts down. My questions: 1. Is this di
-
C55D-a5170 laptop, opening the lid!
Just bought my 1st laptop ever this morning and have dumb question. I can't find anywhere in the quick start quide or online manual as to how you open the lid on this!! There appears to be 2 buttons on the left and right hand side of the front, but