In mdx how to get max date for all employees is it posible shall we use group by in mdx
in mdx how to get max date for all employees is it posible shall we use group by in mdx
example
empno ename date
1 hari 12-01-1982
1 hari 13-06-2000
by using above data i want to get max data
Hi Hari3109,
According to your description, you want to get the max date for the employees, right?
In your scenario, do you want to get the max date for all the employees or for each employee? In MDX, we have the Max function to achieve your requirement. You can refer to Naveen's link or the link below to see the details.
http://www.sqldbpros.com/2013/08/get-the-max-date-from-a-cube-using-mdx/
If this is not what you want, please provide us more information about the structure of you cube, so that we can make further analysis.
Regards,
Charlie Liao
TechNet Community Support
Similar Messages
-
How to Get Missing Dates for Each Support Ticket In My Query?
Hello -
I'm really baffled as to how to get missing dates for each support ticket in my query. I did a search for this and found several CTE's however they only provide ways to find missing dates in a date table rather than missing dates for another column
in a table. Let me explain a bit further here -
I have a query which has a list of support tickets for the month of January. Each support ticket is supposed to be updated daily by a support rep, however that isn't happening so the business wants to know for each ticket which dates have NOT been
updated. So, for example, I might have support ticket 44BS which was updated on 2014-01-01, 2014-01-05, 2014-01-07. Each time the ticket is updated a new row is inserted into the table. I need a query which will return the missing dates per
each support ticket.
I should also add that I DO NOT have any sort of admin nor write permissions to the database...none at all. My team has tried and they won't give 'em. So proposing a function or storable solution will not work. I'm stuck with doing everything
in a query.
I'll try and provide some sample data as an example -
CREATE TABLE #Tickets
TicketNo VARCHAR(4)
,DateUpdated DATE
INSERT INTO #Tickets VALUES ('44BS', '2014-01-01')
INSERT INTO #Tickets VALUES ('44BS', '2014-01-05')
INSERT INTO #Tickets VALUES ('44BS', '2014-01-07')
INSERT INTO #Tickets VALUES ('32VT', '2014-01-03')
INSERT INTO #Tickets VALUES ('32VT', '2014-01-09')
INSERT INTO #Tickets VALUES ('32VT', '2014-01-11')
So for ticket 44BS, I need to return the missing dates between January 1st and January 5th, again between January 5th and January 7th. A set-based solution would be best.
I'm sure this is easier than i'm making it. However, after playing around for a couple of hours my head hurts and I need sleep. If anyone can help, you'd be a job-saver :)
Thanks!!CREATE TABLE #Tickets (
TicketNo VARCHAR(4)
,DateUpdated DATETIME
GO
INSERT INTO #Tickets
VALUES (
'44BS'
,'2014-01-01'
INSERT INTO #Tickets
VALUES (
'44BS'
,'2014-01-05'
INSERT INTO #Tickets
VALUES (
'44BS'
,'2014-01-07'
INSERT INTO #Tickets
VALUES (
'32VT'
,'2014-01-03'
INSERT INTO #Tickets
VALUES (
'32VT'
,'2014-01-09'
INSERT INTO #Tickets
VALUES (
'32VT'
,'2014-01-11'
GO
GO
SELECT *
FROM #Tickets
GO
GO
CREATE TABLE #tempDist (
NRow INT
,TicketNo VARCHAR(4)
,MinDate DATETIME
,MaxDate DATETIME
GO
CREATE TABLE #tempUnUserdDate (
TicketNo VARCHAR(4)
,MissDate DATETIME
GO
INSERT INTO #tempDist
SELECT Row_Number() OVER (
ORDER BY TicketNo
) AS NROw
,TicketNo
,Min(DateUpdated) AS MinDate
,MAx(DateUpdated) AS MaxDate
FROM #Tickets
GROUP BY TicketNo
SELECT *
FROM #tempDist
GO
-- Get the number of rows in the looping table
DECLARE @RowCount INT
SET @RowCount = (
SELECT COUNT(TicketNo)
FROM #tempDist
-- Declare an iterator
DECLARE @I INT
-- Initialize the iterator
SET @I = 1
-- Loop through the rows of a table @myTable
WHILE (@I <= @RowCount)
BEGIN
-- Declare variables to hold the data which we get after looping each record
DECLARE @MyDate DATETIME
DECLARE @TicketNo VARCHAR(50)
,@MinDate DATETIME
,@MaxDate DATETIME
-- Get the data from table and set to variables
SELECT @TicketNo = TicketNo
,@MinDate = MinDate
,@MaxDate = MaxDate
FROM #tempDist
WHERE NRow = @I
SET @MyDate = @MinDate
WHILE @MaxDate > @MyDate
BEGIN
IF NOT EXISTS (
SELECT *
FROM #Tickets
WHERE TicketNo = @TicketNo
AND DateUpdated = @MyDate
BEGIN
INSERT INTO #tempUnUserdDate
VALUES (
@TicketNo
,@MyDate
END
SET @MyDate = dateadd(d, 1, @MyDate)
END
SET @I = @I + 1
END
GO
SELECT *
FROM #tempUnUserdDate
GO
GO
DROP TABLE #tickets
GO
DROP TABLE #tempDist
GO
DROP TABLE #tempUnUserdDate
Thanks,
Shridhar J Joshi
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
How to get the date for the first monday of each month
Dear Members,
How to get the date for the first monday of each month.
I have written the following code
SELECT decode (to_char(trunc(sysdate+30 ,'MM'),'DAY'),'MONDAY ',trunc(sysdate+30 ,'MM'),NEXT_DAY(trunc(sysdate+30 ,'MM'), 'MON')) FROM DUAL
But it look bith complex.
Abhishek
Edited by: 9999999 on Mar 8, 2013 4:30 AMUse IW format - it will make solution NLS independent. And all you need is truncate 7<sup>th</sup> day of each month using IW:
select sysdate current_date,
trunc(trunc(sysdate,'mm') + 6,'iw') first_monday_the_month
from dual
CURRENT_D FIRST_MON
08-MAR-13 04-MAR-13
SQL> Below is list of first monday of the month for this year:
with t as(
select add_months(date '2013-1-1',level-1) dt
from dual
connect by level <= 12
select dt first_of_the_month,
trunc(dt + 6,'iw') first_monday_the_month
from t
FIRST_OF_ FIRST_MON
01-JAN-13 07-JAN-13
01-FEB-13 04-FEB-13
01-MAR-13 04-MAR-13
01-APR-13 01-APR-13
01-MAY-13 06-MAY-13
01-JUN-13 03-JUN-13
01-JUL-13 01-JUL-13
01-AUG-13 05-AUG-13
01-SEP-13 02-SEP-13
01-OCT-13 07-OCT-13
01-NOV-13 04-NOV-13
FIRST_OF_ FIRST_MON
01-DEC-13 02-DEC-13
12 rows selected.
SQL> SY. -
How to get current date for posting date
hi,
how to get current date for posting date ? any sample code ?
ThanksHi......
Use
Select getdate()
for current date.......
Regards,
Rahul -
How to get max date in child table
I have tow tables Departments as the master table and Employees as the child table
The employees table (the child) has employee_hiring_date Field .
I want to get the maximum hiring date in the employee table for every department to make validation over it.
How to make this.It's more or less described in the doc I gave you.
OK, lets do it with your sample.
I assume you have accessors defined to navigate between the master and the detail (in both directions). The accessors on entity level are named
"Employees1" to get the employees of a department
"Departments1" to get the department of an employee
1. In the Departments entity you add a transient attribute "MaxSalary" as type Number, select 'Expression' as 'Value Type' and type "Employees1.max("Salary")" in the value field. Make sure to uncheck the 'Persistent' attribute in the dialog. This will mark the attribute as transient.
2. in the entity Employees open the 'Business Rules' and select the 'Saraly' attribute. Add a rule by clicking the green plus. 'Rule Type' is 'Compare', 'Operator' is 'LessOrEqualTo' and in the 'Compare With' drop down select 'Expression'. In the Dialog enter "Departments1.MaxSalary". Switchto the 'FailureHandling' tab and type in a message you like to see (e.g. 'The Salary is too high!") and save your work. The magic is done in the expression "Departments1.MaxSalary" which selects the department of the employee and gets the value of the attribute 'MaxSalary' which is an other Groovy expression which gets the max salary of all employees in the department.
3. To get the 'MaxSalary' attribute from the entity to the view object, you can open the VO editor and select the 'Attributes' section. Click the arrow down right of green plus and select 'Add Attribute from Entity, shuffle the MaxSalary attribute you see in the Department entity to the right and save your work.
If you now test the app in the Tester try changing the salary of an employee to a value higher then max of the department and you should see your error message.
Timo -
How to get the date for the last day of a week?
Is there a easy way to get the date for the last day of week?
eg a week starts on monday and end on sunday
January 11, 2005 is the start date for the week
January 17, 2005 is the end date for the week
or
say
February 26, 2003 is the start date for the week
March 5, 2003 is the end date for the week
I just need a simple way of figuring that out....
I figured out how to get the start date for the week but just can't get the latter..
formatting of the date is not of a concern.. that I know how to do
thanks in advanceHow about something like the following?
Calendar someDay = new GregorianCalendar(2005,0,11);//2005 Jan, 11
//Note above that January is 0, not 1, as counting starts from 0.
someDay.add(Calendar.DAY_OF_MONTH,6); //add 6 days
java.util.Date lastDayOfWeek = someDay.getTime();
//If someDay was the start of a week, lastDayOfWeek should now be
//the last day of that week.
System.out.println(lastDayOfWeek.toString() ); -
Hi All,
I have a simple query which is below:-
Declare @reportdate date
set @reportdate= (DATEADD(dd,-5,getdate()))
select * from dbo.Table
where date IN (@reportdate)
I need this query to pull the data for the last 3rd business day .So lets say today is monday then i need the data for last week wednesday which is 3 business days back from monday, if today is a tuesday it would be for last thursday ( as 3 business days for
tuesday would be thursday). But if today is wednesday then i need to be last 3rd business day which is last friday and i also need to get the data for saturday and sunday.
Can someone please help me how cani change my filter to do this?
Please let me know if i am still unclear.
ThanksHi SqlDev12,
Based on my understanding on your requirement, you can reference the below sample.
CREATE TABLE BusinessTable
Bdate DATE,
Wd VARCHAR(10)
;WITH Cte(DT,WD) AS
SELECT CAST('20150401' AS DATE),DATENAME(WEEKDAY,CAST('20150401' AS DATE))
UNION ALL
SELECT DATEADD(DAY,1,DT),DATENAME(WEEKDAY,DATEADD(DAY,1,DT)) FROM Cte
WHERE DT<GETDATE()
INSERT INTO BusinessTable SELECT * FROM Cte
SELECT * FROM BusinessTable
SET DATEFIRST 7 -- Set Sunday as the first day of a week
DECLARE @givenDay DATE ='20150415' --Wednesday
SELECT * FROM BusinessTable
WHERE Bdate BETWEEN
--For Monday and Sunday, select last wednesday
(CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
--For Tuesday and Wednesday, last week's Thursday and Friday
WHEN DATEPART(WEEKDAY,@givenDay) IN(3,4) THEN DATEADD(DAY,-5,@givenDay)
--For Thursday and Friday, current week's Monday and Tuesday
WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
--For Saturday, current week's Wednesday
ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
AND
(CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
WHEN DATEPART(WEEKDAY,@givenDay) IN(3) THEN DATEADD(DAY,-5,@givenDay)
WHEN DATEPART(WEEKDAY,@givenDay) IN(4) THEN DATEADD(DAY,-3,@givenDay)
WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
DROP TABLE BusinessTable
If you have any feedback on our support, you can click
here.
Eric Zhang
TechNet Community Support -
ABAP HR: Delete IT0009 data for all employees
HI All,
The reuqirement is to delete IT0009 for all employees from Dev system. Is there any function module which will do it in one go instead of loop and delete each PERNR record.
Thanks.delete pa0009.
for what do you need a FM? -
How to get max date in variable using dynamic query
Hi,
the following code gets all dates from sourcetable i want only max date , so i thought max function can be added and it will work
but still i have to create a table for one value(scalar) can get it in any other effeciant way.
declare
TYPE date_string IS TABLE OF VARCHAR(1000);
date_obj date_string;
BEGIN
EXECUTE IMMEDIATE 'SELECT to_char('''||day1||'-'||month1||'-'||year1||''') FROM '||source_schema||'.'|| sourcetable ||'' bulk collect INTO date_obj;
FOR indx IN date_obj.FIRST..date_obj.LAST loop
dbms_output.put_line(
date_obj(indx));
END loop;
DBMS_OUTPUT.PUT_LINE('Sample output');
END;
yours sincerely944768 wrote:
the following code gets all dates from sourcetableNo it doesn't. What is the datatype of day1, month1 and year1? They cannot be DATE datatypes otherwise your TO_CHAR would fail with all that concatenation going on. And your TO_CHAR is returning a VARCHAR2 datatype... so you cannot say that it is getting all dates... because there are no DATE datatypes returned. It's getting a lot of strings, but certainly not DATE's.
i want only max date , so i thought max function can be added and it will work You can use the MAX function on a DATE datatype, but not on strings (at least not in the way you intend it to work).
Converting it to a DATE before doing the MAX will allow you to get the maximum date (assuming the date format is correct)
EXECUTE IMMEDIATE 'SELECT max(to_date(to_char('''||day1||'-'||month1||'-'||year1||'''),''DD-MM-YYYY'')) FROM '||source_schema||'.'|| sourcetable ||'' bulk collect INTO date_obj;Then you will find have the other issues...
a) you are then going to be fetching your DATEs in to a collection of VARCHAR strings. (Not even VARCHAR2, very poor). This should be DATE datatype
b) you are bulk collecting into a collection, when you are using MAX which will return a single value in your example
And you really should address the design issues:
c) why are day, month and year, not being stored in the database as a single DATE datatype in the first place
d) why does your code not know the name of the table it's querying requiring the use of very poor dynamic SQL techniques.
e) why are you loading data in a collection in expensive PGA memory... what can't you do in SQL that requires you to collect the data into memory first? -
How to get committed date for each component after availability check
Hi,
When I use CO02 to check material availability, I can see committed date in missing part list and missing part overview for each component in production order. I save it and use CO03 to read missing part list again. The committed date is blank?! How to get the committed date for each missing part in production order?
Another question, committed date can be displayed in CO24(missing parts info system)? Thanks in advance!!Rita,
Please check that the PP avail. check has replensh lead time turned on. If RLT is turned off & there is no sufficient stock of material, then system can only committ date of 12/31/9999.
Once you turn on RLT, it will give you some date based on your configured avail check ( that looks at stock or purchase order or production order). That way if there is no sufficient stock of material to satisfy your order system will committ the worst case date which is the RLT.
On CO24 unfortunately there is no field for Committ date. Hence is it not possible to view commit date. You can only view Committ quantity.
i am sure this will help you. Else please come back.
thanks,
Ram -
How to get test data for BAPI_PO_CREATE?
Hi friends,
can anybody please tell me how to generate the test data for BAPI_PO_CREATE?Hi swetha,
Hi,
You could test this scenario with using the Test Message option from RWB.
Or else
You could design the scenario to get the response from BAPI.
i.e BAPI to XI to File or any other application that will be easily avaialble.
But you need receiver system for testing.
Refer the below link it may help you .
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/66dadc6e-0a01-0010-9ea9-bb6d8ca48cc8
Regards
Naveen. -
How to get max(date) with BI Answers?
Hi,
I have a fact table with costs of projects and several dimension tables. The data in the fact table is stored day-based and is related to a time dimension. Additionally there is a relation between the fact table and the project dimension. A project has several dimension attributes like "current"
Now I want to create the following query in BI Answers:
Get the costs to a project where the "current" attribute was set to Y and show the related date.
My thoughts were, that I'm looking in the project dimension where the "current" attribute is set to Y and do a join on the fact table. Therefore I get several dates, because there are more than one day where the project status was set to Y. How can I get the last, highest date?
GreetingsHi,
Maybe you could order by date descending and show the Top N (=1).
Good Luck,
Daan Bakboord -
How to get meta data for email attachments in iphone?
Hi am new to iphone programming,i want to get the meta data for the emails attachments in the inbox of the iphone to be listed the emails with attachment.
Hi..
You have to use SWC_GET_ELEMENT CONTAINER '( string name of your attribute)' your_attribute.
All attributes are part of container issue.. SWC_GET_ELEMENT command can give you these values.
Hope to help... -
HOW TO GET ACTUAL DATE FOR A DATE TYPE ITEM
Hi
We want to get actual date(today) automatically to the date type item on our form page. I should be able to change it also.
thank you very much for help
ömer faruk akyüzlü
in Turkeyhi ömer faruk akyüzlü,
Make the Source Type as PL/SQL Expression or Function
and in the Source Value or Expression
enter SYSDATE Make the item as the date picker of the format whatever u want.
hope this helps u better.
bye
Srikavi. -
How to generate test data for all the tables in oracle
I am planning to use plsql to generate the test data in all the tables in schema, schema name is given as input parameters, min records in master table, min records in child table. data should be consistent in the columns which are used for constraints i.e. using same column value..
planning to implement something like
execute sp_schema_data_gen (schemaname, minrecinmstrtbl, minrecsforchildtable);
schemaname = owner,
minrecinmstrtbl= minimum records to insert into each parent table,
minrecsforchildtable = minimum records to enter into each child table of a each master table;
all_tables where owner= schemaname;
all_tab_columns and all_constrains - where owner =schemaname;
using dbms_random pkg.
is anyone have better idea to do this.. is this functionality already there in oracle db?Ah, damorgan, data, test data, metadata and table-driven processes. Love the stuff!
There are two approaches you can take with this. I'll mention both and then ask which
one you think you would find most useful for your requirements.
One approach I would call the generic bottom-up approach which is the one I think you
are referring to.
This system is a generic test data generator. It isn't designed to generate data for any
particular existing table or application but is the general case solution.
Building on damorgan's advice define the basic hierarchy: table collection, tables, data; so start at the data level.
1. Identify/document the data types that you need to support. Start small (NUMBER, VARCHAR2, DATE) and add as you go along
2. For each data type identify the functionality and attributes that you need. For instance for VARCHAR2
a. min length - the minimum length to generate
b. max length - the maximum length
c. prefix - a prefix for the generated data; e.g. for an address field you might want a 'add1' prefix
d. suffix - a suffix for the generated data; see prefix
e. whether to generate NULLs
3. For NUMBER you will probably want at least precision and scale but might want minimum and maximum values or even min/max precision,
min/max scale.
4. store the attribute combinations in Oracle tables
5. build functionality for each data type that can create the range and type of data that you need. These functions should take parameters that can be used to control the attributes and the amount of data generated.
6. At the table level you will need business rules that control how the different columns of the table relate to each other. For example, for ADDRESS information your business rule might be that ADDRESS1, CITY, STATE, ZIP are required and ADDRESS2 is optional.
7. Add table-level processes, driven by the saved metadata, that can generate data at the record level by leveraging the data type functionality you have built previously.
8. Then add the metadata, business rules and functionality to control the TABLE-TO-TABLE relationships; that is, the data model. You need the same DETPNO values in the SCOTT.EMP table that exist in the SCOTT.DEPT table.
The second approach I have used more often. I would it call the top-down approach and I use
it when test data is needed for an existing system. The main use case here is to avoid
having to copy production data to QA, TEST or DEV environments.
QA people want to test with data that they are familiar with: names, companies, code values.
I've found they aren't often fond of random character strings for names of things.
The second approach I use for mature systems where there is already plenty of data to choose from.
It involves selecting subsets of data from each of the existing tables and saving that data in a
set of test tables. This data can then be used for regression testing and for automated unit testing of
existing functionality and functionality that is being developed.
QA can use data they are already familiar with and can test the application (GUI?) interface on that
data to see if they get the expected changes.
For each table to be tested (e.g. DEPT) I create two test system tables. A BEFORE table and an EXPECTED table.
1. DEPT_TEST_BEFORE
This table has all EMP table columns and a TEST_CASE column.
It holds EMP-image rows for each test case that show the row as it should look BEFORE the
test for that test case is performed.
CREATE TABLE DEPT_TEST_BEFORE
TESTCASE NUMBER,
DEPTNO NUMBER(2),
DNAME VARCHAR2(14 BYTE),
LOC VARCHAR2(13 BYTE)
2. DEPT_TEST_EXPECTED
This table also has all EMP table columns and a TEST_CASE column.
It holds EMP-image rows for each test case that show the row as it should look AFTER the
test for that test case is performed.
Each of these tables are a mirror image of the actual application table with one new column
added that contains a value representing the TESTCASE_NUMBER.
To create test case #3 identify or create the DEPT records you want to use for test case #3.
Insert these records into DEPT_TEST_BEFORE:
INSERT INTO DEPT_TEST_BEFORE
SELECT 3, D.* FROM DEPT D where DEPNO = 20
Insert records for test case #3 into DEPT_TEST_EXPECTED that show the rows as they should
look after test #3 is run. For example, if test #3 creates one new record add all the
records fro the BEFORE data set and add a new one for the new record.
When you want to run TESTCASE_ONE the process is basically (ignore for this illustration that
there is a foreign key betwee DEPT and EMP):
1. delete the records from SCOTT.DEPT that correspond to test case #3 DEPT records.
DELETE FROM DEPT
WHERE DEPTNO IN (SELECT DEPTNO FROM DEPT_TEST_BEFORE WHERE TESTCASE = 3);
2. insert the test data set records for SCOTT.DEPT for test case #3.
INSERT INTO DEPT
SELECT DEPTNO, DNAME, LOC FROM DEPT_TEST_BEFORE WHERE TESTCASE = 3;
3 perform the test.
4. compare the actual results with the expected results.
This is done by a function that compares the records in DEPT with the records
in DEPT_TEST_EXPECTED for test #3.
I usually store these results in yet another table or just report them out.
5. Report out the differences.
This second approach uses data the users (QA) are already familiar with, is scaleable and
is easy to add new data that meets business requirements.
It is also easy to automatically generate the necessary tables and test setup/breakdown
using a table-driven metadata approach. Adding a new test table is as easy as calling
a stored procedure; the procedure can generate the DDL or create the actual tables needed
for the BEFORE and AFTER snapshots.
The main disadvantage is that existing data will almost never cover the corner cases.
But you can add data for these. By corner cases I mean data that defines the limits
for a data type: a VARCHAR2(30) name field should have at least one test record that
has a name that is 30 characters long.
Which of these approaches makes the most sense for you?
Maybe you are looking for
-
When I got my machine two years ago and loaded Firefox, I could scroll with the red button that's on the keyboard of the Lenovo ThinkPad x200. Then, a few months ago, Firefox was updated. Not sure which version. And, now I can't scroll. The keypad sc
-
HT201412 my phone is dead and won't respond to attempts to restore. unknown error 4005
Phone died unknow error 4005 how do I get my serial number to start a chat if I can't get the serial number?
-
Can't see upcoming slide w Moshi HDMI adapter
My Keynote works great with VGA out, see upcoming slide on presenter display. But when using the HDMI out, with Moshi adapter from Apple, I have lost the abilty to see the upcoming slide. Only see what is a mirror image of the main display. Any he
-
Universal Installer does not open
Hello. I try to install the BPEL Process Manager 10.1.3.1.0 on my "Windows 2000 Server" operating system. The prerequisites check runs ok but the Installer doesn't open. Anyone an Idea whats wrong? Thx in advance
-
Query 1 shows less consistent gets but more cost than Query 2..
Hi , SQL> select dname from scott.dept where deptno not in (select deptno from scott.emp) Ðñüãñáììá åêôÝëåóçò Plan hash value: 3547749009 | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | | 0 | SELECT STATEMENT | |