Help in fetching previous timestamp data
i have the following tables in my database
sales
id
product_id,
sale_date,//refers to date_dim.id
sale_time,//refers to time_dim.id
sold_item_count,
date_dim
id,
date,
day,
month,
year,
time_dim
id,
hours,
mins,
sec
i want to fetch the previous sold_item_count of the product using the sale_date,sale_time .can some one help with the query please??
Regards
Murali
You can probably solve this using one of these analytical funtions:
LAG or LEAD
ROW_NUMBER()
or maybe even FIRST_VALUE or LAST_VALUE...
You can find explanations here:
http://www.oracle.com/pls/db112/homepage
Just use the search box in the upper left corner there.
But please post some create table and insert into statements, and the results you want from that data, so we can run tests on our databases and help you in the best possible way.
See: {message:id=9360002} scroll down to *7) Sample Data*
Similar Messages
-
Trying to fetch previous month data
hi ...
i have to develope a report in which cutomer on selecting month from the prompt , i have to show transactions for that selected month,transactions for previous month and growth %.
for fetching previous month data i am using the below formula in column
FILTER(etxnmistopbr.tot_txns USING (etxnmistopb(TIMESTAMPADD(SQL_TSI_MONTH, -1,etxnmistopbr.month_year)))
but it doesnt fetch any result.
i have tried
FILTER(etxnmistopbr.tot_txns USING (etxnmistopbr.month_year= TIMESTAMPADD(SQL_TSI_MONTH,-1,timestamp '@{current_year}{2012}-@{current_month}{07}-31 00:00:00')))
where current_year and current_month are presentation variable
but it throws error as "
HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 46046] Datetime value 2012-8-31 00:00:00 does not match the specified format. (HY000) "
can anyone please help how to retrieve previous month data and current month data
Edited by: 8826 on Sep 27, 2012 4:31 AMI would recommend using Time Series Functions, specifically the Ago function in the RPD. This is precisely what they have been designed for and is a very powerful feature of OBIEE. This removes the need for complex formulae embedded within result columns (which you will have to replicate each time you create a new analysis).
The syntax of the Ago function is as simple as:-
AGO(Measure, Time Dimension Level, Number of Periods Ago) e.g.
AGO(Core."Fact - Project Cost".Cost, Core."Date - Fiscal Calendar"."Fiscal Period", 1)
Please mark if helpful/answered.
Andy. -
Help with Setting Previous Month Date Parameter for SSAS via SSRS
Hi All,
Firstly, any assitance is greatly appreciated.
Now, I am working on developing a report for a business area that will be sent on the first of every month. The report will contain data for all records created in the previous month, current year.
I have been able to successfully implement a default year parameter, which will default to current year-
="[REFERRAL LODGEMENT DATE].[CAL YEAR].&["+CSTR(Year(Today))+"]". However, when I attempt to set a previous month paramater it is not setting when the report is generated. The code I have used
is as follows:
="[REFERRAL LODGEMENT DATE].[CAL MONTH NAME].&["+CSTR(Month(Today)-1)+"]"
CheersBefore you spend more time trying to fix the parameter, let me suggest that you can write MDX to come up previous month data.
if you can't go that route, couple of things to consider for your approach:
1) don't subtract 1 from January that won't work. you'll need to handle it using the ssrs expression.
2) when you use the month function it's going to return a month index so effectively you are passing something like [REFERRAL LODGEMENT DATE].[CAL MONTH NAME].&[7] to SSAS, is that the current format?
you can use the MonthName function to get month names but again make sure that the formatting is right.
to see the parameter value, you can display it on the ssrs report and see if it's the right format.
Paras Doshi (Blog: ParasDoshi.com | Twitter:
@Paras_Doshi ) -
how can i write a query to fetch date for the previous year, given any date inputted by the user ?
(Datatype will be date)Yes, you can make the change in the query. But that would require that the query returns a string, not a date. I showed a couple replies ago how to add a TO_CHAR call to return a string in a particular format.
If you want to return a date, you have to accept that a date has many valid display formats. It is up to the client to determine how to make the date human readable. If the client is SQL*Plus, the client application defers to the individual user's preferences as expressed by the NLS_DATE_FORMAT. That is incredibly useful behavior since preferred date formats are culturally dependent. A European will read the string '3/6/11' as June 3, 2011 while an American reads it as March 6, 2011. Honoring the NLS_DATE_FORMAT makes it easy to let every user see dates in the format they prefer.
Justin -
Help needed in getting the previous Quarter Data
Hello folks,
I have this procedure where i have to modify the current procedure in the following manner:
I need to get rid of the variables p_start and p_end so that i cannot see them in the crystal report and include the Frequency in the procedure to get the Data based on the Dates.
and Main requirement is" If the Frequency is Quarterly " it should get the previous quarter Data, if "Frequency is monthly" it should return the previous month data.Can anyone please let me know where shud i make changes. Am including the procedure for refernce. Any help is appreciated
Thanks a millioin,
CREATE OR REPLACE PROCEDURE hcsc_recovery_report_h(report_record in out cr_return_types.gen_cursor,
p_start string,
p_end string)
IS
v_startdate date;
v_enddate date;
BEGIN
v_startdate := to_date(p_start, 'YYYY/MM');
v_enddate := last_day(to_date(p_end, 'YYYY/MM'));
open report_record for
select --distinct r.recovery_id
r.event_id,
r.event_case_id,
c.client_id,
c.client_code,
c.client_name,
b.branch_group_code,
b.branch_group_description,
g.employer_group_code,
g.employer_group_name,
e.client_policy_identifier,
e.date_of_incident,
e.event_type_code,
sum(nvl(r.amount, 0)) as amt_received,
nvl(sum(case
when r.amount >= 0 then
rd.fees
else
rd.fees * (-1)
end),
0) as fees,
ec.close_date, *001* commented
(case
when ec.close_date <= to_date(to_char(v_enddate, 'MMDDRRRR') || '235959',
'MMDDRRRR HH24MISS') then
ec.close_date
else
null
end) as close_date, --*001* added
get_case_value(ec.event_id, ec.event_case_id, v_enddate) as case_value,
nvl(etl.fee_percent_flag, 'N') workmans_comp,
max(to_char(r.recovery_date, 'FMMonthYYYY')) Year_Month,
max(to_char(r.recovery_date, 'YYYYMM')) Y_M,
max(to_date(to_char(r.recovery_date, 'MMYYYY'), 'MM/YYYY')) date_MY
from recovery r,
recovery_detail rd,
event e,
client c,
branch_group b,
employer_group g,
event_case ec,
event_type_lookup etl
where r.event_id = e.event_id
and r.event_case_id = ec.event_case_id
and ec.event_id = e.event_id
and rd.recovery_id(+) = r.recovery_id
and r.recovery_date between v_startdate and
to_date(to_char(v_enddate, 'MMDDRRRR') || '235959',
'MMDDRRRR HH24MISS')
and e.client_id = c.client_id
and g.client_id = c.client_id
and b.client_id = c.client_id
and g.employer_group_id(+) = e.employer_group_id
and b.branch_group_id(+) = g.branch_group_id
and e.event_type_code = etl.event_type_code -- SST 130852 04/14/09
group by r.event_id,
r.event_case_id,
c.client_id,
c.client_code,
c.client_name,
b.branch_group_code,
b.branch_group_description,
g.employer_group_code,
g.employer_group_name,
e.client_policy_identifier,
e.date_of_incident,
e.event_type_code,
ec.close_date,
get_case_value(ec.event_id, ec.event_case_id, v_enddate),
nvl(etl.fee_percent_flag, 'N')
having sum(nvl(r.amount, 0)) <> 0
order by c.client_code,
b.branch_group_code,
g.employer_group_code,
r.event_case_id;
Edited by: user11961230 on Oct 20, 2009 9:02 AMuser11961230 wrote:
1. I want to get rid of the p_start and p_end. So how do i declare the v_startdate and v_enddate in the following part?
v_startdate := to_date(p_start, 'YYYY/MM');
v_enddate := last_day(to_date(p_end, 'YYYY/MM'));I'm not sure what you mean by "declare".
In PL/SQL, "declare" means state (at the beginning of a block) that there will be a certain variable with a certain name (such as v_startdate) and datatype (such as DATE). You're already declaring the variables v_startdate and v_enddate correctly, right before the BEGIN statement.
Declaring a variable is not the same as initializing it, that is, giving it a value for the first time. Your next question seems to be about initializing..
2. where exactly shud i include the logic that u have mentioned. sorry a dumb questionIn place of the two assignment statments that reference p_start and p_end.
3. This time am gonna use frequency instead of report_type so that i will get rid of the p_start and p_end from the procedure.Do you mean you want to pass an argument (called frequency) that tells if you want a quarterly or a mionthly report, just like the variable report_type in my example?
If so, replace report_type in my example with frequency.
I think you want something like this:
CREATE OR REPLACE PROCEDURE hcsc_recovery_report_h
( report_record in out cr_return_types.gen_cursor
, frequency IN VARCHAR2
IS
-- Declare local variables:
v_startdate date;
v_enddate date;
BEGIN
-- Initialize v_startdate and v_enddate, depending on frequency
IF frequency = 'QUARTERLY'
THEN
v_startdate := TRUNC ( ADD_MONTHS (SYSDATE, -3)
, 'Q'
v_enddate := TRUNC (SYSDATE, 'Q');
ELSIF frequency = 'MONTHLY'
THEN
v_startdate := TRUNC ( ADD_MONTHS (SYSDATE, -1)
, 'MM'
v_enddate := TRUNC (SYSDATE, 'MM');
END IF;
-- Subtract one second from v_enddate
v_enddate := v_enddate - ( 1
/ (24 * 60 * 60)
open report_record for
select --distinct r.recovery_id
r.event_id,
and r.recovery_date BETWEEN v_startdate
AND v_enddate
...When you post formatted text on this site (and code should always be formatted), type these 6 characters:
(small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
Edited by: Frank Kulash on Oct 20, 2009 2:37 PM
Changed query to use BETWEEN -
Can someone help with a previous post labeled "Writing to a data file with time stamp - Help! "
Can someone possibly help with a previous post labeled "Writing to a data file with time stamp - Help! "
Thankswhats the problem?
Aquaphire
---USING LABVIEW 6.1--- -
Previous month data in WebI Report
Hi All,
I have a universe created on a Bex Query. I don't have any variables created in the Bex Query. I have to create a WebI report with Calendar Year/Month as selection and depending on what user enters, i have to display Cost for the month entered by the user and cost for (month -1 ). For eg. if the user enters Feb 2009, then the report should display Cost for Jan 2009 and Feb 2009. I have created a filter for Calendar Year/Month. How do i bring previous month data in the report ? I don't have to modify the Bex Query. I have to achieve it on the BO side. Can you guys help on this problem.
Thanks,
SaachiHi,
There is a restriction in BO when you use it with SAP.
When the user filters the data for FEB 2009, you will not be able to get data for JAN 2009 as it does
not go again to the Bex query to fetch this data.
The only workaround as of now to this is to bring all the data using Bex query by having a filter
at the BO Query level where you say Cal year/month key = (From prompt) or
Cal year/month key <> #.
This is because it considers Cal year/month as string and so even at the universe level we will not
be able to create a previous month formula.
I hope this helps.
Thanks,
Kartik -
How to fetch year till date value for earning for current ,last and year
hi,
how to fetch year till date value for earning for current ,last and year before that from payroll result
plz reply soon,
pratyushDear Pratyush,
Pick this from CRT.
Use LDB PNPCE & Fire event GET PAYROLL &
then you can pick from CRT.
Hope this helps.
Kindly reward in case useful.
Regards & Thanks,
Darshan Mulmule -
How to show a report for 'Previous Month' Data
Hi Gurus,
I have a requirement, where i have to default my report to show previous month data.
Scenario:
My prompts by Default are set to CURRENT (current year,quarter,month). once the user logs in, the report should display data for month 'Nov' instead of 'Dec'.
I tried using TIMESTAMPADD() in the formula , but it didn't work, though i don't see any error. Not sure if i 'm missing something.
Is there a way to achieve this.I 'm using OBIEE 11.1.1.6.
Any help is highly Appreciated ! Please.
Thanks,
RamyaFrom what you wrote I am assuming the user can manually save the report results to the Excel file.
If your report uses ALV Grid it is possible to export the data to a spreadsheet (one of the functions available in the ALV tool bar).
If you have used WRITE statements it is also possible to save the output as a spreadsheet (menu System -> List -> Save), but the latter will not produce as nice a spreadsheet if the data don't form a matrix. In other words, some work may be necessary in the spreadsheet afterwards before it has the format your user wants. -
Happily running OS 10.2.1.2141 on my Z10 (STL100-3). I was thrilled to see the hub's Pinch Selection Criteria option in 10.2.1 but did not have the occasion to try it. Then this weekend, my mailbox got flooded with email notices from our alert system and I was facing having to delete hundreds of emails the old tedious way, multi-select each email one at a time and hit the delete option. Well, that's when I tried to use the hub's new pinch selection option to "hide" my read messages. I then held the date line to select all the previous messages and hit the delete option which asked my if a really wanted to delete those messages. I confirmed by choice and poof! nothing happened. I tried several times to no avail, even trying with flagged messages. It looks like you can't delete messages while in Pinch Selection view if you select them via the Select previous (hold date line) method. It does work if you select/multi-select the messages manualy but what's the point then?....
So, unless i'm doing it wrong, this appears to be a bug.
Regards,
Francis.....fpaquin wrote:
that should be the point of the pinch selection criteria and you're select by sender.... let's see if anyone can reproduce the "bug" on their handsets or better yet, BlackBerry confirms it's a bug or poor design......
when I pinch and hold a date bar, I get the trash can... do you not?
fpaquin wrote:
Yup, that's the tedious way I've always used, ok for a few emails, unacceptable for hundreds of emails.....
Oh, yea for hundreds. Do you get hundreds each day you need to delete?
Once you get caught up on your deleting, then your daily upkeep should be a reasonable low effort.
Anyways, that's how it works.
If you feel it is an OS issue... what OS are you on?
1. If any post helps you please click the below the post(s) that helped you.
2. Please resolve your thread by marking the post "Solution?" which solved it for you!
3. Install free BlackBerry Protect today for backups of contacts and data.
4. Guide to Unlocking your BlackBerry & Unlock Codes
Join our BBM Channels (Beta)
BlackBerry Support Forums Channel
PIN: C0001B7B4 Display/Scan Bar Code
Knowledge Base Updates
PIN: C0005A9AA Display/Scan Bar Code -
Need to show Previous months data in report
Hi All,
I have a crystal report 2011 which shows monthly Cash data. It has 3 other columns like Previous 3 months cash data, previous 6 months cash data, Previous 12 months cash data in report.
My report also has two parameters- start date and end date. If I give Start date as 1/1/2012 and end date as 12/31/2013 (two years date range) then correct data comes in all columns and for 2013 year, correct data is coming for Previous 12 months column. But if I give only one month date range like start date as 1/1/2013 and end date as 01/31/2013, then it is not showing correct data for these 3 columns - Previous 3 months cash data, previous 6 months cash data, Previous 12 months cash data. Ideally as per requirement, it should calculate previous months data regardless of parameter values and put data in respective columns.
Any help/suggestion? Any trick which can help me to show correct data in all columns no matter what date range or months I am taking in parameters.
Is it mandatory to have previous 12 Months data in report to calculate column-Previous 12 months Cash data?
Thanks,
RemiHi Remi,
You can try like this:
I have given a some suggestions i.e You just take one parameter only because u can imagine 3 columns previous data display correctly i.e From Date
Month parameter is also a alternate option.
For Ex: Column1: From Date - 90 Days/3 Months - we get the three months previous data correctly etc.
Finally, create a stored procedure that returns the required columns and does all the calculations on the database side.
Follow abhilash suggestion as well.
Useful threads: Crystal Report Parameter Issue
Pull Last 6 months of data
Month to date data for Previous month
How to find current month, previous month Net Sales by means of formula?
Thanks,
DJ -
Migrating Sybase "timestamp" data type to Oracle DB
Hi,
We are migrating huge Application currently running on Sybase database
to Oracle 10.2.0.3 (500+ Tables and Stored Procedures).
Have following questions regarding this Migration.
1) Many of the Sybase Tables have column which is of Sybase data type "timestamp".
Do you have any recommendation what is the data type to be used in Oracle for
migrating "timestamp" data type in Sybase?
2) How should we migrate existing data and business logic residing in Sybase for
data columns of Sybase data type "timestamp" ?
Given below are details on how we use Sybase timestamp Column in our Application
and we are trying to arrive at the best Solution that is possible for migrating
all those Tables and related business logic to Oracle.
We have following Control Table in Sybase which has column of timestamp data type and
some other Business keys.
sp_help EQP_IES_CRE_TIMESTAMP (This is similar to desc <table> command in Oracle)
EQP_IES_CRE_TIMESTAMP,dbo,user table
default,Nov 14 2001 10:39AM
CRE_TIMESTAMP ,timestamp,8,,,0,,,,0
REF_NUM ,char,30,,,0,,,,0
REC_UPD_DT ,datetime,8,,,1,,,,0
EQP_IES_CRE_TIMESTAMPI1,clustered, unique located on default, CRE_TIMESTAMP, REF_NUM, REC_UPD_DT,0,0,0,
Following is the overall logic used in Sybase
-- Step 1: Based on Event, populate Control Table with new Row.
-- CRE_TIMESTAMP timestamp Column gets auto-populated by Sybase
insert EQP_IES_CRE_TIMESTAMP (REF_NUM, REC_UPD_DT)
values (@uuid_ref_num, @event_cre_dt)
Since CRE_TIMESTAMP is auto-populated, it does not appear in above INSERT statement.
-- Step 2: Store timestamp value populated by Sybase in previous step,
-- to variable @event_timestamp. This value would be referenced
-- later in other SQL statements
select @event_timestamp = CRE_TIMESTAMP
from EQP_IES_CRE_TIMESTAMP
where REF_NUM = @uuid_ref_num
and REC_UPD_DT = @event_cre_dt
-- Sample value for @event_timestamp could be '001c0000182f2089'
-- It is not very readable or understandable
-- Step 3: Delete Control Table entry made in Step 1
delete EQP_IES_CRE_TIMESTAMP from EQP_IES_CRE_TIMESTAMP
where CRE_TIMESTAMP = @event_timestamp
-- Step 4: Make use of saved timestamp value from Step 2 to trigger queries
-- against other Tables that have timestamp Columns
-- Some sample queries are as shown below
delete eqp_staging
where event_timestamp > @event_timestamp;
insert into eqp_movement values(@event_timestamp, ......other columns) ;
Any idea how above Table and logic could be migrated to Oracle DB
We would also like to know how data values that currently exist
in Sybase Tables should be populated in Oracle .
Any suggestions or tips would be greatly appreciated
Thanks
AuropremHi All,
Thanks for your responses.
We have decided on Solution to migrate "timestamp" Column from Sybase to Oracle, that is
specific to our Application needs.
Following is what we decided:
1) Create RAW Column in Oracle which would contain data Replicated from Sybase "timestamp" Column as is.
2) Create additional Column of INTEGER data type to store number equivalent of Sybase "timestamp" column
which would be more usable and consummable in Oracle as compared to RAW datatype.
3) Write Row-Level INSERT/UPDATE Trigger on migrated Oracle Table to populate INTEGER Column using
SQL Function TO_NUMBER(<raw_column_value>, 'xxxxxxxx').
4) Applications that access this Table, upon migration to Oracle, will now start referencing INTEGER Column
newly defined, and populated via Trigger.
Please let us know if you see any issues with this approach
Thanks
user641521 -
Sample ABAP routine code to load only previous month data in INFOPACKAGE
Hi all,
I want to create one ABAP routine in InfoPackage (Variables change to selection values with background processing) for 0CALMONTH ( Calender year month) so that whenever this infopackage is executed it should fetch only previous month data.
Can anyone please provide any sample code for that.
Thanks in advance.
Uday shankar.Hi
Please check with below code, hope this will resolve your issue
WHEN: 'ZLASTP'.
CLEAR: h_period, h_gjahr.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = sy-datum
I_MONMIT = 00
i_periv = 'AF'
IMPORTING
e_buper = h_period
e_gjahr = h_gjahr
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF h_period = '001'.
h_gjahr = h_gjahr - 1.
h_period = '012'.
ELSE.
h_period = h_period - 1.
ENDIF.
CLEAR l_s_range.
CONCATENATE h_gjahr h_period INTO l_s_range-low.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range. -
How to get previous day data if i dont have current day data.
Hello Gurus,
I have a stock levels data in ODS. when there is no movements, we are not getting any stocks into ODS. So we have to get previous day data as it is for current day data into another ODS.
Could you please help me in this regard.
Thanks in advance,
RamaRama -
0CALDAY can't help us in this scenario .
Step 1 :
To do this - You have to add one ZDATE (InfoObject ) to 1st ODS. ZDATE is updated by itself from current date of system when ever you are loading data to 1st ODS.
Step 2:
You have to do full update to 2nd ods.At the selection screen of InfoPackage (from 1st ODS to 2nd ODS ) you have to write following code for ZDATE.
pseudo Code:
1) Select fields "Rec_INSERT","Time stamp","Request Status" and "Request ID" where ICUBE = ODS1 from table "RSMONICDP"
2) Populate above selected fields data in INTERNAL TABLE
3) Sort INTERNAL TABLE by Time stamp .
4)
If (Record Count = ' 0 ' for current date in internal table )
update records from ODS1 to ODS2 where ZDATE = "yesterday date"
else
update records from ODS1 to ODS2 where ZDATE= "today date"
endif.
Make sure this is full update not delta update from ODS1 to ODS2
I am sorry, I m not good in Coding but I am sure if u use this logic,You can meet your requirement.
I hope you can understand my logic. Let me know if you have any questions,
Anesh B . -
Hi all
Please help in writing a query to get the previous week data.
If the input date is sysdate then it should return values for previous week Monday to Sunday.
Whatever the input it should get the value for previous week from Monday to Sunday.
Thanks
JoIW is the formatter for the "Iso-Week"
ISO = international standard organization
See also: http://en.wikipedia.org/wiki/ISO_week
Main thing is that it will always start with monday. The weeknumber might be different then for ww format. This doesn't matter in your case. But you migh want to do some experiments with to_char(sysdate,'IW'), to_char(sysdate,'WW').
Trunc(<datevale>,'IW') will cut the date back to the first day of this iso-week.
select to_char(sysdate-365,'IW') IW , to_char(sysdate-365,'WW') WW from dual;
IW WW
37 36Edited by: Sven W. on Sep 9, 2010 2:29 PM
Maybe you are looking for
-
How to file a complaint regarding rewards
I have opted for Verizon residential plan in March 2013. During the process, Verizon customer support person helped me to get the service. There was $250 reward promo going on at that time for getting the service for 2 years contract. During each ste
-
I've upgraded to new version of itunes on windows 7 PC - no link to my library - HELP!!
Hi There So, upgraded to new itunes - no link to my previous library though some recent itunes purchases there. Have tried draggin music file into Itunes - only connects first song on first album. tried dragging individual albums - again only first
-
How do i undisable my iphone if its never been synced to a computer
How do i undisable my iphone if its never been synced to a computer
-
PSE12 does not recognize HP Photosmart C410 scanner
PSE12 does not recognize HP Photosmart C410 scanner.
-
Mac os x setup assitant keeps coming up
So I upgraded my macbook the other day and I just shut it down for the first time since then and now when ever I type in my passwork it kicks me to the setup assitant. I did the setup about 10-15 times and it still kicks me back to enter my password