Date difference query
I have a below table
student_id course startdate enddate amount
1 .net 12-05-2014 30-7-2014 5000
1 sql 1-06-2014 30-06-2014
3000
2 informtica 1-06-2014 31-07-2014 10000.
so on
output sholud be the amount has to split accross months
student_id course startdate enddate amount month split_amount
1 .net 12-05-2014 30-7-2014 5000
may 1250
1 .net 12-05-2014 30-7-2014
5000 june 1875
1 .net 12-05-2014 30-7-2014 5000
july 1875
1 sql 1-06-2014 30-06-2014
3000 june 3000
2 informtica 1-06-2014 31-07-2014 10000 june
4918
2 informatica 1-06-2014 31-07-2014 10000 july
5082
please suggest me any query..
Hi,
i think this may help you,
first i created the temp table (you can replace it with your data table)
Declare @t Table (student_id Int,course Varchar(100),startdate DateTime,enddate DateTime,amount Decimal(12,0))
Insert Into @t
Select 1,'.net','2014-05-12','2014-07-30',5000
Union
Select 1,'sql','2014-06-01','2014-06-30',3000
Union
Select 2,'informtica','2014-06-01','2014-07-31',10000
;with cte As (
Select t.*,cd.LatinMonthTitle,t.amount/Count(cd.id) Over(Partition By student_id,course) As AmountPerDay,cd.LatinMonthId--*Count(cd.id)
From @t As t
Inner Join @DateIndex As cd On cd.LatinDate Between t.StartDate And t.EndDate)
Select student_id,course,startdate,enddate,amount,LatinMonthTitle,Cast(Count(1)*AmountPerDay As Decimal(12,0)) As AmountPerMonth
From cte
Group By student_id,course,startdate,enddate,amount,LatinMonthTitle,AmountPerDay,LatinMonthId
Order By 1,2,LatinMonthId
You need to know about my @DateIndex Table!
you should build this table and it's useful many time.
declare @dateindex table(Id Int Identity(1,1),LatinDate DateTime,LatinMonthId Int,LatinMonthTitle Varchar(100))
declare @i int=0
declare @FirstDate datetime='2014-01-01'
declare @CurrDate datetime=@FirstDate
while @i<1000
begin
Set @CurrDate=DATEADD(day,@i,@FirstDate)
insert into @dateindex
(LatinDate,LatinMonthId,LatinMonthTitle)
Select @CurrDate,DATEPART(MONTH,@CurrDate),DATENAME(MONTH,@CurrDate)
set @i+=1
end
Select * From @dateindex
Similar Messages
-
Date Difference Query Syntax Formatted Search
Hi Experts,
My client renders a service(warehousing of Cargo) on time and material basis,therefore the Quantity column of the AR Invoice represents the number of days the cargo was warehoused.
I want to create a formatted search with reference to a query on this field to help me compute the number of days automatically. The number of days is normally calculated by Subtracting the the Admission date(Serial Number Details Table "OSRI", field "InDate" from the document date of the invoice) from the AR invoice document date.
Considering that the Item is serial number managed, the item serial number will connect the Serial Number details table to the AR Invoice table.
Can anybody help me with the syntax of the query that will achieve the above for me.
Waiting to hear from you .
ThanksIf you have many serial numbers for an item, there will be no way to identify which serial number was actually selected in the invoice till the time the Invoice is added.
So knowing the Serial Number that was selected on that Invoice is important and what you select in the Serial number selection window on the Invoice is stored in temporary location and cannot be referencing by looking into OSRI table.
If there are multiple serial numbers with different InDate's, how could you calculate?
Is there a Delivery Step? Delivery > Invoice
OR
Do you copy SO > AR Invoice directly
Suda -
Query report with date difference.
Hi Expert,
I'm using below query to monitor unreleased checks. we have a policy that the holding period for unreleased check is 5 working days.
SELECT T2.[CardCode], T2.[CardName], T0.[TransId], T0.[DueDate], T1.[Credit], T1.[U_DisBank], T4.[Name], DateDiff(dd,T0.[DueDate],GetDate()) As 'OverDue Days' FROM OJDT T0 INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId INNER JOIN OCRD T2 ON T1.ShortName = T2.CardCode INNER JOIN "@HOFFICE" T4 ON T1.U_Disbank = T4.Code WHERE T1.[Credit] !=0 AND T0.[DueDate] >=[%0] AND T0.[DueDate] <=[%1] AND T1.[balduedeb]+T1.[balduecred] !=0 ORDER BY T4.[Name]
However I would like to exclude weekends in computing date difference. Can you please help me modify my query code?
Thanks,
Arlmi2000Hi,
A simple solution will be change DateDiff(dd,T0.DueDate,GetDate()) to DateDiff(dd,T0.DueDate,GetDate())*5/7+1
This can cover all the weekends. If you need to be exact that including public holiday, the coding will be longer.
Thanks,
Gordon -
I have the data format in the customer contact table as DD/MM/YYYY
ex. 11/10/1981
how can i write SQL for calculate date difference from that date in table until now(SYSDATE) to know that
how long they be my customer ?
in format yy years mm month dd days
ex. 15 years 3 month 12 day
I have created this query....
SELECT customer_id, first_name ,cust_date,
TRUNC((TRUNC (sysdate)-cust_date)/365)| |' years '||
TRUNC(MOD(TRUNC(sysdate)-cust_date,365))||' days 'AS MDATE FROM Customer;
but it show only years and date...
ex. 31 years 165 days
how can i calculate for result "31 years X month Y day" ?Here's a starting point...
SQL> select sysdate, sysdate - 1234 from dual
2 /
SYSDATE SYSDATE-1
09-AUG-06 24-MAR-03
SQL> select trunc(trunc(months_between (sysdate, sysdate - 1234))/12) yrs,
2 mod(trunc(months_between(sysdate, sysdate - 1234)), 12) mnths,
3 sysdate - add_months((sysdate - 1234), trunc(months_between(sysdate, sysdate - 1234))) dys
4 from dual
5 /
YRS MNTHS DYS
3 4 16
SQL> Edited by: BluShadow on Nov 24, 2008 3:51 PM
Darn it! way too slow. :D -
Date Difference between to date formula variable
Hi Expert,
I have create two formula variable one for Document Date and another one for Goods reciept date
and through formula variable I am subtracting these two formula variable and getting the no. of days between
document date and GR date.
This Shows me the correct value for one document date because i am filtering my query according to document
date,
while i am giving the date range for document date is shows me incorrect result. bucause document date formula
variable contains only one date.
Eg. i am giving the document date range like 01.02.2010 - 28.02.2010.
In document date formula variable it contains only 01.02..2010 and GR date formula variable it contain correct
value, thats why the date difference is incorrect because those PO which has PO date like 12.02.2010 for that Doc
formula variable bring the same date like 01.02.2010.
Please tell me the solution
Thanks and Regards
Lalit KumarHi Expert,
Actually i have created two formula variable on for PO date and another for GR date
and i've restrict the query through PO date.
while i am taking the single PO date in Selection parameter it showing me correct difference
eg: Selection Parameter for PO: 01.01.2010
But while i am taking the date interval for PO date
eg: 01.01.2010-30.01.2010
PO No: XXXXX123 , Doc date: 01.01.2010 GR date: 7.01.2010 then date difference is : 6
PO No: XXXXX432, Doc date: 03.01.2010 GR date: 8.01.2010 then date difference is : 7 but it is 5
Thanks and Regards
Lalit Kumar -
HI,
I ran a query on a database few times which had different execution plan (basically first I ran with index and later without index).
I tried to cross verify the data from DBA_HIST_SQLSTAT and DBA_HIST_ACTIVE_SESS_HISTORY for that particular query and found there were two different SQL ID for same SQL statement. Ideally if execution plan changes then only the plan hash value or hash value changes but in this scenario we have two different SQL ID with different Plan hash value or hash value.
I need to understand why do we have this data difference?
==================================================================================================
SQL> select snap_id,instance_number,sample_time,session_id,module,sql_plan_hash_value from dba_hist_active_sess_history where sql_id='9zgyc24gzsgpz';
SNAP_ID INSTANCE_NUMBER SAMPLE_TIME SESSION_ID MODULE SQL_PLAN_HASH_VALUE
9478 2 07-JAN-11 13.09.11.540 503 SQL*Plus 2290340548
9478 2 07-JAN-11 13.23.42.616 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.12.735 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.22.746 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.32.759 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.42.770 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.52.782 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.26.02.795 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.26.12.811 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.26.22.823 514 SQL*Plus 3778028574
SQL> select snap_id,sql_id,plan_hash_value from dba_hist_sqlstat where sql_id='9zgyc24gzsgpz' ;
SNAP_ID SQL_ID PLAN_HASH_VALUE
9478 9zgyc24gzsgpz 2290340548
==================================================================================================
Thanks
DevendraHi,
DBA_HIST_ACTIVE_SESS_HISTORY is a sampling of the sampling already done in ASH, however data used for AWR "snapshots" is completely separate and works just like Statspack did, so it can capture all SQL in the shared pool at the time of the snapshot if you tell it to - it is not limited to just the SQL sampled by ASH. Also AWR does not capture every statement executed in the interval,even if the statement was not aged out from V$SQL.
DBA_HIST_ACTIVE_SESS_HISTORY displays the history of the contents of the in-memory active session history of recent system activity, DBA_HIST_SQLSTAT displays historical information about SQL statistics
Regards,
Ugur -
Date differences if one of the field not presenting
Hi All,
I have two attributes start date and end. I have created formula replacement variable.
some times one of the field coming as blank, in such acase system writing some garbage value but i need blank.
How to resolve this issue.
Reagrds,
J BHi,
You can create a new formula in query designer with a condition such that date difference doesn't fall in the invalid value. If it that invalid value put the result as '0'.
http://help.sap.com/saphelp_nw04/helpdata/en/23/17f13a2f160f28e10000000a114084/frameset.htm
If the output is showing as '0' for the invalid values then in the query properties select the Display zeroes as Do Not Display Zeroes.
http://help.sap.com/saphelp_nw04/helpdata/en/1e/99ea3bd7896f58e10000000a11402f/frameset.htm
Hope this helps.........
Rgs,
Ravikanth. -
Hi,
I want to find the duration of stock in quality.
Is there any direct formula available to calculate the date difference.
Or I need to create a variable for this.
Thanks, JeetuHi,
You can also calculate date difference at query level using replacement path variables.
Check this link:-
http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
regards,
Pruthvi R -
Hello Guys, how are you.
I'm facing a problem whan I try to get the difference between the max and min date of a KF.
Mi requirement is like this:
Min Date Max Date Difference (max - min)
20/06/2008 26/06/2008 6
My query result is like this:
min date max date difference
20/06/2008 26/06/2008 0
It seems like the formula for getting the difference between the other 2 formulas is not working, because I'm using the function of aggregattion, based on some characteristic, in order to have the max value of the date in one formula, and then have the min value of the date in other formula (the KF store for date is the same, that's the reason i have to use aggregation in order to calculate min and max value).
Then I have a third formula to calculate the difference between the min value and the max value, but it seems that its not working because of the aggregation.
Can you please give me some ideas of how can i obtain the desire result.
THANKS IN ADVANCEHi Carmonia,
(a) If you want to perform calculations on DATE and if both dates are characteristic infobjects, then you can go for Formula Replacement Path.
1. Create a New Formula or CKF and then select a Formula Variable. Right click and select New Varaible.
2. Now create a Variable for one of the Characteristic of Date type with processing type Formula - Replacement path. Select Replace with 'Key' and Dimension as 'Date'. Similarly create another formula replacement variable for another characteristic.
3. Now you can taken both these variables in calculations(such as A-B).
(b) If you are using key figure for the dates, then try by using DATE function in Data Functions of New Formula.
Example: DATE(kfig_MaxDate)-DATE(kfig_MinDate). Also try DATE(kfig1_MaxDate-kfig2_MaxDate).
***Assign points if useful.
Thanks,
Sasi -
I am trying to calculate date difference when in analyzer it data difference value always shows some weird number 732,755. When i execute the same query in portal it shows the correct value. Has it anything to do with BEx settings. Did anyone face such an issue. Please respond
Hi Ganesh,
I appreciate for the response. But its just not a display setting in Designer. Here the date difference calcluations gives me the same number 732,755 for all different numbers like 208 days, 19 days.... No matter what the date difference be its just the same weird number popping up.
Could you please suggest me anything more.
Thanks. -
Date difference problem.....
Hi,
I am calculating the date difference with the Formula variables.
My requirement is to find the rocords, where date difference is 0.
, Means same date.
But I am facing one problem while testing the query.
If for the two date , if both the columns are not having any value,
it contains # , and if I calculate the diffence of this,
This is also coming as 0 in the Date difference column.
Can somebody let me know how to rectify/avoid this situation?
Thanks , JeetuHi Jeetu,
According to your requirement, if record is there, there should be at leaset one date value say "Starting Date".
If "ending date" value is blank, the formula returns a junk/garbage value.
If both the date values are available, the formula returns the number of days corectly.
But, both the date values are blank, there should not be any record in such case. If you see this case in your data base,
that can be either wrong data record or you need to exclude such condition from your query.
Thanks,
Kiran. -
Not able to access data in Query
Hi,
I have loaded data using DTP from 2 different source systems.
One is 3.x emulated datasource and the other is New 7.0 datasource.I have loaded data sucessfully in to DSO.Built a query on same.
But when iam executing the query by material as selection criteria.Iam not able to found data in query from one source system.The same data is available in DSO.Please needed in this regard.Hi Venkat,
After extracting data into DSO check the request whether active or not.
Check data in DSO in contents.
If is there any restrictions on info providers in Queries.
Let us know status clearly.......
Reg
Pra -
How Can I use a Variable in Data Controls query. Frank Kindly check...
Hii,
I am using JDeveloper 11g ADF BC.
My Requirement is that I hv a login screen which is taken from [http://blogs.oracle.com/shay/simpleJSFDBlogin.zip].
I hv attached BC in this application. I want to use the login usercode in the next pages after login screen. Next screen contains 3 list items which will be populating based on the user. So I created <af:selectOneChoice> using the BC( Just drag & dropped the column into the page from the data controls). But in the data control i want to use this usercode for passing the condition. Now Data is coming without any condition.
So How can I use the usercode in the Data controls query.
When I tried to display the usercode in the next page it is showing by binding the value. its code is follows
<af:outputText value="#{backing_getUser.uid}"
The program for checking the username & Password is follows.
package login.backing;
import oracle.adf.view.rich.component.rich.RichDocument;
import oracle.adf.view.rich.component.rich.RichForm;
import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import java.sql.*;
import java.util.List;
import java.util.Map;
import oracle.adf.view.rich.component.rich.output.RichMessage;
import oracle.jdbc.OracleDriver;
public class GetUser {
private RichInputText uid;
private RichInputText pid;
private RichCommandButton commandButton1;
private RichInputText inputText1;
private RichInputText inputText2;
public void setUid(RichInputText inputText1) {
this.uid = inputText1;
public void setPid(RichInputText inputText2) {
this.pid = inputText2;
public RichInputText getUid() {
return uid;
public RichInputText getPid() {
return pid;
public void setCommandButton1(RichCommandButton commandButton1) {
this.commandButton1 = commandButton1;
public RichCommandButton getCommandButton1() {
return commandButton1;
public String login_action() {
// Add event code here...
String user = this.getUid().getValue().toString();
// String pass = inputText2.getValue().toString();
String pid = this.getPid().getValue().toString();
Connection conn;
conn = getConnection();
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery ("SELECT usercode FROM guser where usercode = '"+user.toUpperCase()+"' and pwd=F_TEST('"+pid.toUpperCase()+"')");
if (rset.next()) {
conn.close();
return "good";
conn.close();
} catch (SQLException e) {
System.out.println(e);
return "bad";
public static Connection getConnection() throws SQLException {
String username = "ACCTS";
String password = "ACCTS";
String thinConn = "jdbc:oracle:thin:@SERVER1:1521:G5PS";
DriverManager.registerDriver(new OracleDriver());
Connection conn =
DriverManager.getConnection(thinConn, username, password);
conn.setAutoCommit(false);
return conn;
public void setInputText1(RichInputText inputText1) {
this.inputText1 = inputText1;
public RichInputText getInputText1() {
return inputText1;
public void setInputText2(RichInputText inputText2) {
this.inputText2 = inputText2;
public RichInputText getInputText2() {
return inputText2;
-----Hi,
I didn't look at the example, but if you want to secure your application then you should use container managed security. Read this .
Anyway, you could add this before return "good"; in your login_action()
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("username", user);Then, you can access this from anywhere in the application by using #{sessionScope.username}.
Pedja -
Error in saving large value with the data input query
Hi,
I am trying to save a large value in 0Quantity using the data input query into a realtime infocube
e-g
123456789.1234
Error says too many digits.
When i try to save 8 digits before the decimal point ,no error, if it is 9digits before decimal it's thro' error.
Is there any limitation before the decimal.
i know that 0Quantity can take 17 digits including the sign.
Any suggestions.?
regards,
ramtry budgetting in thousands in stead of units? (setting on query itself)
D -
Hi
I have two date columns and I want one logical column which contains difference of those two DATE columns.
But I found that we dont have any Date difference or Date Add functions in OBIEE Answers.
Can anyone tell me any work around for the Date ADD/DIFF functions?
Thanks
RadhaOr if you want database specific date functions, use EVALUATE and then specify the database functions. Check my blog entry here http://oraclebizint.wordpress.com/2007/09/10/oracle-bi-ee-10133-support-for-native-database-functions-and-aggregates/
Thanks,
Venkat
http://oraclebizint.wordpress.com
Maybe you are looking for
-
User exit while VL02N , changing delievery date..reflects PO delivery date
Hi, Can you please suggest EXIT which triggers while changing delivery date (LIKP-LFDAT) of outbound delivery through TCODE VL02N should reflect in its corresponding purchase order delivery date ( ME22N at item level field (EKET-EINDT).. I tried in U
-
WHAT IS YOUR IDEAL CELL PHONE AND TABLET/ULTRABOOK/LAPTOP COMBO?
I'd like to see what everyone here thinks is the best CELL PHONE and TABLET/ULTRABOOK/LAPTOP combination to own this year now that the CES show is coming to a close. So post up what you think is the ideal combination from what has been announced. M
-
How do I delete Pages 08 from my mac
I have a old copy of Pages 08 and a newer copy of Pages 09. How do I get all files into 09 and delete 08. Thanks
-
MM Smartforms:GoodsIssue Slip/Transfer Posting/Return Delivery/Physical Cou
MM Smartforms Hi Gurus, Can any one guide me on the smartforms related Material Management - with the smartform names for the below mentioned items along with the driver program name 1.Goods Issue slip 2.Transfer posting 3.Return Delivery 4.Physical
-
Hello all For a Business partner (TCode - BP), in its Credit Mgmt segment ---> in "CREDIT WORTHINESS DATA" tab, I need to fill the "Rating" field. I want to have values in the F4 help for that field. How I can do so ? 1. If I maintain a rating proced