How can I do a loop within a select statement
This is my query
Select distinct
s.First_NM,
s.Last_nm,
s.Date_of_birth,
i.Class_ID,
i.Enrollment_begn_dt,
i.Enrollment_end_dt,
SUBSTR(TO_CHAR(i.Enrollment_begn_dt, 'MMDDYYYY'),1,2) AS MONTH,
SUBSTR(TO_CHAR(i.Enrollment_end_dt, 'MMDDYYYY'),5,4) AS YEAR,
CASE WHEN TO_NUMBER(SUBSTR(TO_CHAR(i.Enrollment_begn_dt, 'MMDDYYYY'),1,2)) >= '5'
THEN (TO_NUMBER(SUBSTR(TO_CHAR(i.Enrollment_begn_dt,'MMDDYYYY'),5,4)) + '1')
ELSE TO_NUMBER(SUBSTR(TO_CHAR(i.Enrollment_begn_dt,'MMDDYYYY'),5,4)) END AS Enrollment_cycle
From student s, institution iEnrollment cycles are defined as follows
05/1/2004 to 04/30/2005 == 2005
05/1/2005 to 04/30/2006 == 2006
05/1/2006 to 04/30/2007 == 2007
05/1/2007 to 04/30/2008 == 2008
This is the current output
First_NM Last_nm Date_of_birth Class_ID Enrollment_begn_dt Enrollment_end_dt Enrollment_cycle
Jake Brown 11/10/1999 Blue_007 7/10/2004 6/10/2007 2005
Amy Burrell 5/1/1999 Blue_007 1/20/2005 5/1/2005 2005
Char Goblin 12/24/1999 Blue_007 3/3/2006 7/10/2020 2006My desired output is - which I am having difficulty creating
First_NM Last_nm Date_of_birth Class_ID Enrollment_begn_dt Enrollment_end_dt Enrollment_cycle
Jake Brown 11/10/1999 Blue_007 7/10/2004 4/30/2005 2005
Jake Brown 11/10/1999 Blue_007 5/1/2005 4/30/2006 2006
Jake Brown 11/10/1999 Blue_007 5/1/2006 4/30/2007 2007
Jake Brown 11/10/1999 Blue_007 5/1/2007 6/10/2007 2008
Amy Burrell 5/1/1999 Blue_007 1/20/2005 5/1/2005 2005
Char Goblin 12/24/1999 Blue_007 3/3/2006 4/30/2006 2006
Char Goblin 12/24/1999 Blue_007 5/1/2006 4/30/2007 2007
Char Goblin 12/24/1999 Blue_007 5/1/2007 4/30/2008 2008
Char Goblin 12/24/1999 Blue_007 5/1/2008 4/30/2009 2009I trying to break up each record in the previous table into multiple enrollment cycles based on how it is decribed.
Also note the last record - the cycle ends at 4/30/2009 ----This is because the enrollment_cycle will only stop at the current year + 1 (i.e if we assume current year to be 2008 then the cut off will be year will be 2009 hence I have 4/30/2009 instead of 7/10/2020
I am thinking this can be done with a for loop but I am not sure how to do it. without hard coding the dates.
Please help me!!!!!
Hi ,
I forgot the DATE_OF_BIRTH.
Regards
Salim.
WITH t AS
(SELECT 'Jake' first_nm, 'Brown' last_nm, to_date('11/10/1999','mm/dd/yyyy') date_of_birth,
'Blue_007' class_id, to_date('07/10/2004','mm/dd/yyyy') enrollment_begn_dt,
to_date('06/10/2007','mm/dd/yyyy') enrollment_end_dt, '2005' enrollment_cycle
FROM DUAL
UNION ALL
SELECT 'Amy', 'Burrell', to_date('05/01/1999','mm/dd/yyyy'), 'Blue_007', to_date('01/20/2005','mm/dd/yyyy'),
to_date('05/01/2005','mm/dd/yyyy'), '2005' enrollment_cycle
FROM DUAL
UNION ALL
SELECT 'Char', 'Goblin', to_date('12/24/1999','mm/dd/yyyy'), 'Blue_007', to_date('03/03/2006','mm/dd/yyyy'),
to_date('07/10/2020','mm/dd/yyyy'), '2006' enrollment_cycle
FROM DUAL)
SELECT FIRST_NM,LAST_NM,DATE_OF_BIRTH,ENROLLMENT_BEGN_DT,ENROLLMENT_END_DT,ENROLLMENT_CYCLE
FROM T
MODEL
RETURN UPDATED ROWS
PARTITION BY (FIRST_NM,LAST_NM)
DIMENSION BY (1 ANNEE )
MEASURES(ENROLLMENT_BEGN_DT,DATE_OF_BIRTH,ENROLLMENT_CYCLE,LEAST( ENROLLMENT_END_DT, TRUNC(SYSDATE)) ENROLLMENT_END_DT)IGNORE NAV
( ENROLLMENT_BEGN_DT[FOR ANNEE FROM EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) TO EXTRACT ( YEAR FROM ENROLLMENT_END_DT[1]) INCREMENT 1] = TO_DATE(TO_CHAR(ENROLLMENT_BEGN_DT[1],'MM/DD')||'/'||CV(ANNEE),'MM/DD/YYYY'),
ENROLLMENT_END_DT [FOR ANNEE FROM EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) TO EXTRACT ( YEAR FROM ENROLLMENT_END_DT[1]) INCREMENT 1] = TO_DATE('04/30'||(CASE WHEN EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) =
EXTRACT ( YEAR FROM ENROLLMENT_END_DT[1]) THEN CV(ANNEE) ELSE CV(ANNEE)+1 END) ,'MM/DD/YYYY'),
ENROLLMENT_CYCLE [FOR ANNEE FROM EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) TO EXTRACT ( YEAR FROM ENROLLMENT_END_DT[1]) INCREMENT 1] =CV(ANNEE) ,
DATE_OF_BIRTH [FOR ANNEE FROM EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) TO EXTRACT ( YEAR FROM ENROLLMENT_END_DT[1]) INCREMENT 1] =DATE_OF_BIRTH[1])
SQL> WITH t AS
2 (SELECT 'Jake' first_nm, 'Brown' last_nm, to_date('11/10/1999','mm/dd/yyyy') date_of_birth
3 'Blue_007' class_id, to_date('07/10/2004','mm/dd/yyyy') enrollment_begn_dt,
4 to_date('06/10/2007','mm/dd/yyyy') enrollment_end_dt, '2005' enrollment_cycle
5 FROM DUAL
6 UNION ALL
7 SELECT 'Amy', 'Burrell', to_date('05/01/1999','mm/dd/yyyy'), 'Blue_007', to_date('01/20/2
005','mm/dd/yyyy'),
8 to_date('05/01/2005','mm/dd/yyyy'), '2005' enrollment_cycle
9 FROM DUAL
10 UNION ALL
11 SELECT 'Char', 'Goblin', to_date('12/24/1999','mm/dd/yyyy'), 'Blue_007', to_date('03/03/2
006','mm/dd/yyyy'),
12 to_date('07/10/2020','mm/dd/yyyy'), '2006' enrollment_cycle
13 FROM DUAL)
14 SELECT FIRST_NM,LAST_NM,DATE_OF_BIRTH,ENROLLMENT_BEGN_DT,ENROLLMENT_END_DT,ENROLLMENT_CYCLE
15 FROM T
16 MODEL
17 RETURN UPDATED ROWS
18 PARTITION BY (FIRST_NM,LAST_NM)
19 DIMENSION BY (1 ANNEE )
20 MEASURES(ENROLLMENT_BEGN_DT,DATE_OF_BIRTH,ENROLLMENT_CYCLE,LEAST( ENROLLMENT_END_DT, TRUNC(S
YSDATE)) ENROLLMENT_END_DT)IGNORE NAV
21 ( ENROLLMENT_BEGN_DT[FOR ANNEE FROM EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) TO EXTRACT
( YEAR FROM ENROLLMENT_END_DT[1]) INCREMENT 1] = TO_DATE(TO_CHAR(ENROLLMENT_BEGN_DT[1],'MM/DD')
||'/'||CV(ANNEE),'MM/DD/YYYY'),
22 ENROLLMENT_END_DT [FOR ANNEE FROM EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) TO EXTRACT
( YEAR FROM ENROLLMENT_END_DT[1]) INCREMENT 1] = TO_DATE('04/30'||(CASE WHEN EXTRACT ( YEAR FROM
ENROLLMENT_BEGN_DT[1]) =
23
EXTRACT ( YEAR FROM
ENROLLMENT_END_DT[1]) THEN CV(ANNEE) ELSE CV(ANNEE)+1 END) ,'MM/DD/YYYY'),
24 ENROLLMENT_CYCLE [FOR ANNEE FROM EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) TO EXTRACT
( YEAR FROM ENROLLMENT_END_DT[1]) INCREMENT 1] =CV(ANNEE) ,
25 DATE_OF_BIRTH [FOR ANNEE FROM EXTRACT ( YEAR FROM ENROLLMENT_BEGN_DT[1]) TO EXTRACT ( Y
EAR FROM ENROLLMENT_END_DT[1]) INCREMENT 1] =DATE_OF_BIRTH[1])
26 ;
FIRS LAST_NM DATE_OF_BI ENROLLMENT ENROLLMENT ENRO
Jake Brown 1999-11-10 2004-07-10 2005-04-30 2004
Jake Brown 1999-11-10 2005-07-10 2006-04-30 2005
Jake Brown 1999-11-10 2006-07-10 2007-04-30 2006
Jake Brown 1999-11-10 2007-07-10 2008-04-30 2007
Amy Burrell 1999-05-01 2005-01-20 2005-04-30 2005
Char Goblin 1999-12-24 2006-03-03 2007-04-30 2006
Char Goblin 1999-12-24 2007-03-03 2008-04-30 2007
Char Goblin 1999-12-24 2008-03-03 2009-04-30 2008
Char Goblin 1999-12-24 2009-03-03 2010-04-30 2009
9 ligne(s) sélectionnée(s).
Similar Messages
-
How can I create "Sub Queries" in a select statement?
Hi all,
I need to create reports, which are not based on a single table but on several "sub-queries".
This would be the code, but I don't know how to solve that problem...
SELECT OGBI.*
FROM
(((select "OSSRALL"."FORECAST_OWNER", sum
("OSSRALL"."TOTAL_OPPORTUNITY_AMOUNT")
from "#OWNER#"."OSSRALL" "OSSRALL",
"#OWNER#"."TEAM_MAIN" "TEAM_MAIN",
"#OWNER#"."MA_MAIN" "MA_MAIN"
group by "OSSRALL"."FORECAST_OWNER")OGBI.APPSME1)
where "OSSRALL"."OPP_CLASS" = (EX_OTHERS)),
-- more are following
"#OWNER#"."OSSRALL" "OSSRALL",
"#OWNER#"."TEAM_MAIN" "TEAM_MAIN",
"#OWNER#"."MA_MAIN" "MA_MAIN"
WHERE
("MA_MAIN"."MA_NAME"||', '||"MA_MAIN"."MA_FIRST_NAME"||' Mr'
like "OSSRALL"."FORECAST_OWNER" or
"MA_MAIN"."MA_NAME"||', '||"MA_MAIN"."MA_FIRST_NAME"||' Mrs'
like "OSSRALL"."FORECAST_OWNER" or
"MA_MAIN"."MA_NAME"||', '||"MA_MAIN"."MA_FIRST_NAME"
like "OSSRALL"."FORECAST_OWNER") and
("OSSRALL"."SALES_GROUP"="TEAM_MAIN"."NAME") and
("MA_MAIN"."MA_ID"=:P17_VB1)
thx a lot for your help.
kind regards Jan
Message was edited by:
Jan RabeJan
Please can you post the full select statement and the DDL to create the tables? Or, provide someone access to the app on the Oracle server.
We can probably make these much more readable using table aliases and removing the owner unless you are doing this across schemas or via a wizard?
It looks like you are missing joins in your query - is this what you mean by subqueries? It is a good idea to move the join up before the WHERE clause if you can as this makes the query easier to manage.
Phil -
How can I Sync same contacts within Google account & iphone, ipad?
My boss has iPhone 4, ipad & Blackberry, Iphone & ipad enable icloud. All devices sync with google account. After some days we found duplicates contacts & some same contacts 4/5 save in Google account.
How can I Sync same contacts within Google account & above devices?
Thanks,
QamrulSync your iPad with computer iTunes.
Note: your contacts should be in computer Outlook (Windows) or Contacts (Mac) application.
If you have iCloud configured in iPhone, do the same for iPad.
Setttings > iCloud >
Account: your Apple ID
Contacts: ON
Documents & Data: ON -
How can i access the stepname within a steps post-expression?
How can i access the stepname within a steps post-expression?
i only saw the step-id of the step: Step.TS.Id
is there a pssibility to get the stepname from the id?
thank you!Hi Fischer,
use the expression NameOf(Step).
Regards
Ray Farmer
Regards
Ray Farmer -
HOW can i rotate the loop as many lines of multi line container in BPM
Hi All
I have to send an idoc to 2 Receivers by spliting the message.
Based on the occurance of a particular source segments i need to create those many instance of targets.
IDOC ---> Rec1 (More than one message instance)
---> Rec2 (More than one message instance)
I have taken messages of Receiver into a multi line container1
and messages of Receiver 2 into another multi line container2.
HOW can i rotate the loop as many lines of multi line container.
Thans
PrasadHi Raj
There are two webservices are 2 receivers.
In the idoc there is specific segment , which occurs unbounded,Each occurence we Need to check the value of a particual field and send to corresponding Receiver.
For Ex:
ZE1KONH (1..Unbounded)
>MSFGN =004 --> Rec1
>> MSFGN==0009 Rec2
It could be like , 1 or more segm for Rec1 and 1 or more segm for Rec2
all are for Rec1 or All are for Rec2.
so in the tranformation we need to put all message of Rec1 in corresponding multiline container as well for Rec2. Then i need to send to correspongind Receiver.
So here i need to send all splited messages to appropriate receivers -
How can I add a group within Contacts
How can I add a group within my Contacts list?
This has been a highly requested iOS feature for years. Nothing like that is available yet without third party apps.
-
How can I inset a hyperlink within a sticky?
How can I inset a hyperlink within a sticky so that it can be clicked on and link directly to the hyperlinked site?
Using Adobe Acrobat 9 Pro, version 9.0 running on Mac OSX version 10.5.6 with a HP 2840 printerDick --
I ran into the same hyperlink issue with some of my PDF documents that were signed, precluding any changes. After exhausting avenues in Acrobat, on a whim I typed an updated path in Word, made it a hyperlink, then copied the link and pasted it into a sticky note. Wonder of wonders, it worked. Who'd have thought Word is actually good for something other than writing letters?
Gary -
How can I rotate a pattern within a shape?
How can I rotate a pattern within a shape?
To the left of the 1 key, right below the esc key. Has the ~ and ` on it.
That key has ° and ¨ on it on my keyboard and it doesn't work.
But I found it by holding down the < key (to the left of Z).
So now I can rotate etc. patterns manually after about 3 decades of doing it numerically through the dialogue :-)
You live and learn.
Thanks Scott,
Steve.
(Maybe this helps other people with funny keyboards. What say Jacob and Monika? Or maybe theirs are even funnier.) -
How can i embed an image within a table
how can i embed an image within a single column of a table
noticed this question elsewhere and have seen that the trick is to copy and paste not drag & drop
incase anybody else was wondering -
how can I view my photos within my iCloud account? I don't have an icon for that, like I do for Calendar, for instance.
There is no "Online Gallery" feature in iCloud.
You can use photostream instead to snyc your pictures across your devices, but not to the internet. -
I have a street address and a billing address. A question is posed with a checkbox — "Is the billing address the same as the street address?" If Yes is checked, the street address automatically fills the billing fields. If No is checked, the user must fill in new information. In both the street address and billing addres, the State field is a drop-down list. How can I get the drop-down list selection in the street address State also be selected in drop-down list for the billing address State?
Has anyone done this?
-
How can I receive the value of a selected item in the backing bean
I have a table in a jspx file.
When I go to the detail page I want to do something with the value of the currentrow.
I want do a calculaction of the value of ClbId.
How can I receive the value of the selected ClbId in my backing bean
<af:table value="#{bindings.Searchteamlist.collectionModel}"
var="row" rows="#{bindings.Searchteamlist.rangeSize}"
first="#{bindings.Searchteamlist.rangeStart}"
emptyText="#{bindings.Searchteamlist.viewable ? 'No rows yet.' : 'Access Denied.'}"
selectionState="#{bindings.Searchteamlist.collectionModel.selectedRow}"
selectionListener="#{bindings.Searchteamlist.collectionModel.makeCurrent}"
rendered="#{backing_FirstFlag_Club_Club.searchFirstTimeClub_Club_AdresAndereClubs == false}">
<af:column sortProperty="Matricule" sortable="true"
headerText="#{bindings.Searchteamlist.labels.Matricule}">
<af:outputText value="#{row.Matricule}"/>
</af:column>
<af:column sortProperty="ClbId" sortable="true"
headerText="#{bindings.Searchteamlist.labels.ClbId}">
<af:outputText value="#{row.ClbId}">
<f:convertNumber groupingUsed="false"
pattern="#{bindings.Searchteamlist.formats.ClbId}"/>
</af:outputText>
</af:column>
<af:column sortProperty="Nom" sortable="true"
headerText="#{bindings.Searchteamlist.labels.Nom}">
<af:outputText value="#{row.Nom}"/>
</af:column>
<f:facet name="selection">
<af:tableSelectOne text="Select and">
<af:commandButton text="Submit"
action="club_AdresAndereClubsDetail">
<af:setActionListener from="#{row}"
to="#{processScope.row}"/>
</af:commandButton>
</af:tableSelectOne>
</f:facet>
</af:table>hi tde
Using an Expression Language helper class like this one from Steve Muench ...
http://radio.weblogs.com/0118231/stories/2006/12/18/sourceForMyFavoriteElHelperClass.html
... you could write something like this in your backing bean:
Integer vClbId = (Integer)EL.get("#{row.ClbId}");(Make sure to cast it to the correct type.)
success
Jan Vervecken -
How can i set dynamice for week on Selection screen..pls help me..Urgent
Hi..All
please Help me .. i am very confused..
i need to set a varient for week which is dynamic on selection screen.
b) Week from current week to current week + 2. (<b>Dynamic selection)</b>how can i set dynamice for week on Selection screen,,
how can i do this..i am alrady set dynamice variant for Date.. there is option for D.. but in case of week there is a no option.
pls help me..urgent
thamks in advance.
mayukhHi,
I think the way out is use the dynamic select option while setting up the varinat and use sy-datum to sy-datum+9 which should essentially serve the purpose.
While saving the variant, for that particular date field check the Selection variable checkbox, then Choose D
option and then choose current days + or - option from there.
Rgds,
HR -
How can I contact a human to get a statement of some kind to get a reimbursement from my company?
Hi Tina,
You can get the invoices for your order by logging in to www.adobe.com using your adobe id and password and going to 'My orders' option.
Thanks! -
iPhone 4S with the latest updates 8.1.3 (12B466) installed.
When I switch back to an ongoing application, from the switcher, it reverts to its own 'homepage' rather than the stay at the state/stage I left it at.
How can I force applications to maintain the current state?
I am in the process of getting enough screenshots to demonstrate further.ios7 keeps refreshing apps after switching
solcwd
Maybe you are looking for
-
ITunes will not start on my Toshiba Satellite Computer
I have installed Itunes 10.2.2 to my new Toshiba Satellite computer and when I open it I get an error message that says, "QuickTime was not found. QuickTime is required to run ITunes. Please uninstall Itunes and reinstall. I've done this about 6 time
-
Can't open xls file created by windows excel
when i try to open a xls file created by windows excel, my numbers (3.2.2) tells me that " 'file name' cannot be opened' please help, thank you!
-
this time with a dead line {tonight} :( anyway the user is supposed to enter "i am user i am user" & the program will output i 2 am 2 user 2 this is the code import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public
-
I just updated Safari with version 5.1.10 and now I cannot use "open location". Anyone else having this problem and are there any solutions?
-
How to delete all but visible area of a layer
I think this should be simple, but I can't figure out how to do it. I have a container I'm trying to draw with a border around it, to this border I'm going to apply various effects so it needs to remain a separate layer from the container. To crea