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 sincerely
944768 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?
Similar Messages
-
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 dataHi 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 -
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 table data column by column dynamically
Hi ,
first of all
i have something like this
cursor sys_cursor is
select * from sys.all_objects;
v_data varchar2(200);
fetch sys_cursor
into v_owner, v_object_name, v_subobject_name, v_object_id, v_data_object_id, v_object_type, v_created, v_last_ddl_time, v_time_stamp, v_status, v_temporary, v_generated, v_secondary;
v_data := v_owner || ' ' || v_object_name || ' ' || v_subobject_name || ' ' ||
v_object_id || ' ' || v_data_object_id || ' ' ||
v_object_type || ' ' || v_created || ' ' || v_last_ddl_time || ' ' ||
v_time_stamp || ' ' || v_status || ' ' || v_temporary || ' ' ||
v_generated || ' ' || v_secondary;
encrypt(v_data);
it is ok for "sys.all_objects" but i need to modify this for all tables
so , i need to know column names of table and type of it and value of it
then i need to get column values by one by and encrypt it.
i used dbms_sql and succeed to find column name and type
however , i couldnt get the values.i can't use dbms_sql.column_values because i find column type dynamically.
what can i do?
how can i get table data by row
and then for each row , i need to get values of columns by one by and encrypt those values.
any idea is appriciated.
thanks
AykutDynamic SQL is the solution. Right from getting the column names, their data types to passing the string to encrypt function that you have.
You will need to handle datatypes like LONG, LOB etc... as they cannot be concatenated with strings.
Also, you need to manage dates and numbers.
Obviously this would be very complicated code.
Even if you decide to code the procedure to encrypt tables one by one, still you need to make this procedure dynamic to handle above situations. -
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 server date and time using java code
Hi,
I'm new to java. I have one doubt about getting date and time of the server. can anyone give some sample code to get that.
thanks in regards
Gopi.you need 2 things
1. something on the application server which exposes the servers time/date
2. something on the client which makes use of your time service
for instance, you could write a ServerTimeServlet that clients can call to get the time according to the server. or, if you've got a database in the server, often database software will provide a Time procedure or similar that does this, so you can use a simple SQL query to get the latest time -
How to get max date field in the query
Hi,
We uploads the data into the cube every week.
Basically we are planning to put some ticker on the query. This ticker will show the user, upto which date the data is available in the cube.
I want the query, which will show me only the maximum date (maximum 0calday) from the infocube in the report.
This in turn, I will use in the ticker and make use of it.
Can anyone please help in making this query.
Thanks
Ramesh Ganjiif 0CALDAY is used as a characteristic then you have to convert that as a key figure using a replacement path variable.
Please see the below link for changing 0CALDAY as a key figure using Replacement path
http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
https://websmp106.sap-ag.de/~sapdownload/011000358700001963972003E/HowToCalcWithAttr.pdf
Now you have to create an exception "Top N Rows" based on the replacement path variable created above.
This will solve your problem.
Regs
Gopi.
Award points if it helps ... -
How to get exact date using to_date
Hi all
how to get exact date over there
select TO_DATE(TRUNC(PLLA.CREATION_DATE),'DD-MON-YYYY'),TRUNC(PLLA.CREATION_DATE),round(PLLA.CREATION_DATE),
TO_DATE(round(PLLA.CREATION_DATE),'DD-MON-YYYY'),TO_DATE(PLLA.CREATION_DATE,'DD-MON-YYYY'),PLLA.CREATION_DATE,
TO_DATE(TRUNC(PLLA.CREATION_DATE)),TO_DATE(round(PLLA.CREATION_DATE))
from po_line_locations_all plla.
In one of the plsql program i want to compare the creation date with given date where as creation date is in Timestamp formatHi,
Use trunc or to_char with masking like 'dd/mm/yyyy' format. If this does not solve your problem then do post your sample input and sample output. As I am unable to make out what is your actual problem.
Regards -
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'> -
HI All,
I have an query, i have data like how to get filtered data
i have data like below
we have started this report with below data for Oct 2014 to Dec 2014
QUARTER
STATE
COUNT
Oct 2014 - Dec 2014
U.P
70
Oct 2014 - Dec 2014
M.P
0
Oct 2014 - Dec 2014
BIHAR
3
Oct 2014 - Dec 2014
MAHA
50
Oct 2014 - Dec 2014
RAJ
3
so it was very easy to generate report
then we get data for Jan 2014 to March 2014
QUARTER
STATE
COUNT
Oct 2014 - Dec 2014
U.P
70
Oct 2014 - Dec 2014
M.P
0
Oct 2014 - Dec 2014
BIHAR
3
Oct 2014 - Dec 2014
MAHA
50
Oct 2014 - Dec 2014
RAJ
3
Jan 2014 - Mar 2014
U.P
77
Jan 2014 - Mar 2014
M.P
1
Jan 2014 - Mar 2014
BIHAR
4
Jan 2014 - Mar 2014
MAHA
77
Jan 2014 - Mar 2014
RAJ
5
so we applied filter on quarter manually for generating the report
now we have data like below
QUARTER
STATE
COUNT
Oct 2014 - Dec 2014
U.P
70
Oct 2014 - Dec 2014
M.P
0
Oct 2014 - Dec 2014
BIHAR
3
Oct 2014 - Dec 2014
MAHA
50
Oct 2014 - Dec 2014
RAJ
3
Jan 2014 - Mar 2014
U.P
77
Jan 2014 - Mar 2014
M.P
1
Jan 2014 - Mar 2014
BIHAR
4
Jan 2014 - Mar 2014
MAHA
77
Jan 2014 - Mar 2014
RAJ
5
Apr 2014 - Jun 2014
U.P
186
Apr 2014 - Jun 2014
M.P
18
Apr 2014 - Jun 2014
BIHAR
74
Apr 2014 - Jun 2014
MAHA
189
Apr 2014 - Jun 2014
RAJ
68
now as per new requirement they want only this quarter data of Apr 2014 to Jun 2014
Apr 2014 - Jun 2014
U.P
186
Apr 2014 - Jun 2014
M.P
18
Apr 2014 - Jun 2014
BIHAR
74
Apr 2014 - Jun 2014
MAHA
189
Apr 2014 - Jun 2014
RAJ
68
and requirement like we have to automate this process . means report should contain only current quarter value.
so my query is how to achieve this
please suggest
I am using SAP BO 3.1
Thanks in advance
JeetHi Jeet,
You can try this-
Create variable
V_Quarter= if Left(<QUARTER>,3)="Jan" then 1 elseif Left(<QUARTER>,3)="Apr" then 2 elseif Left(<QUARTER>,3)="Jul" then 3 else 4
V_Year= Right(<QUARTER>)
V_CurrQuarter=Quarter(CurrentDate())
V_CurrYear=Year (CurrentDate())
Apply filter on report
V_Quarter= V_CurrQuarter and V_Year=V_CurrYear
-Anuj -
How to get changed data in ALV in Web Dynpro for ABAP
METHOD on_data_check .
DATA:
node_spfli TYPE REF TO if_wd_context_node,
node_sflight TYPE REF TO if_wd_context_node,
itab_sflight2 TYPE if_display_view=>elements_sflight.
node_spfli = wd_context->get_child_node( name = if_display_view=>wdctx_spfli ).
node_sflight = node_spfli->get_child_node( name = if_display_view=>wdctx_sflight ).
CALL METHOD node_sflight->get_static_attributes_table
IMPORTING
table = itab_sflight2.
this code is ..get all data(changed and not changed)
but i want get changed data only, not all data.
how to get changed data?
Edited by: Ki-Joon Seo on Dec 27, 2007 6:04 AMHi,
To get only the changed data in the ALV grid of a WD, you need to capture the "ON_DATA_CHECK" of the ALV grid.
To this please do the following in the ALV initialization of the ALV table settings :
lr_table_settings->set_data_check(
IF_SALV_WD_C_TABLE_SETTINGS=>DATA_CHECK_ON_CELL_EVENT ).
You may also do this:
lr_table_settings->set_data_check( IF_SALV_WD_C_TABLE_SETTINGS=>DATA_CHECK_ON_CHECK_EVENT)
The above two ways would depend on when do you need to check for the changed data. If you want to check the data as soon as it is entered, then use the first method. Else, use the second method.
You need to register an EVENT HANDLER for this event.(You may do this in your VIEW or Component Controller).
In this Event handler, you would find an importing parameter R_PARAM which is a ref type of IF_SALV_WD_TABLE_DATA_CHECK.
The attribute T_MODIFIED_CELLS of this interface IF_SALV_WD_TABLE_DATA_CHECK will contain the modified cells of the ALV with the old & new values. -
How to get all events from calendar using calcalendar store framework.
Hello,
I have two problems with calcalendar store framework programming.
1. I need all the event which are present in iCal calendar.Event may be present in year 2025 or 2050. and if the event is recurring then i need only one event.
2. if the event is recurring then i need only one event within the calendar event predicates (start date and end date). I am not suppose to give the occurrence date for event.
How can I implement this with CalCalendar store framework.
Thanks And Regards,
xmax.Hi,
Per my knowledge, there is not a method to get all the recurring events using CAML query in one request.
Here is a thread with the similar question for your reference:
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/eed6be6d-c9ff-4d01-80de-8a4b67d3d7a5/use-caml-to-get-all-recurring-events-from-a-calendar
We can get all the calendar list events at first, then filter all the recurring event from the result set.
Best Regards
Dennis Guo
TechNet Community Support -
How to get the data from pcl2 cluster for TCRT table.
Hi frndz,
How to get the data from pcl2 cluster for tcrt table for us payroll.
Thanks in advance.
Harisumanth.ChPL take a look at the sample Program EXAMPLE_PNP_GET_PAYROLL in your system. There are numerous other ways to read payroll results.. Pl use the search forum option & you sure will get a lot of hits..
~Suresh -
How to get the data from Pooled Table T157E.
Hi Experts,
How to get the data from Pooled Table T157E.
Any help.
Thanks in Advance,
Ur's Harsha.create some internal table similar to T157E and pass all data as per SPRAS.
After that use internal table in your program as per the requirement.
Regds,
Anil -
How to get purchasing data from SAP R/3 to OWB (Oracle warehouse builder).
Hi,
My name is Pavan Tata. I work as a SAP BW developer. Here is the situation at my client place. Client decided to retire BW system and wants to replace with OWB(Oracle warehouse). In all this currently we have purhchasing application in BW production system and wants to move this application to OWB for the same type of reporting what they are getting currently.
Here is my question:
How to get purchasing data from SAP R/3 to OWB(Warehouse) with initial full loads and deltas mechanism in the same way as we do in BW.
Please help on this, also send me any documentation about this if you have.
Thanks,
Pavan.Hello,
here is a short report which converts S012 entries to strings with separator semicolon. Perhaps this will help you?
Regards
Walter Habich
REPORT habitest2 LINE-SIZE 255.
TYPES:
strtab_t TYPE TABLE OF string.
CONSTANTS:
separator VALUE ';'.
DATA:
it_s012 LIKE s012 OCCURS 0,
wa_s012 LIKE s012,
strtab TYPE strtab_t,
strele TYPE string.
SELECT * FROM s012 INTO TABLE it_s012 UP TO 100 ROWS.
PERFORM data_to_string
TABLES
strtab
USING
'S012'. "requires it_s012 and wa_s012
LOOP AT strtab INTO strele.
WRITE: / strele.
ENDLOOP.
*& Form data_to_string
FORM data_to_string TABLES strtab TYPE strtab_t
USING ittab TYPE any.
DATA:
h_zaehler TYPE i,
line_str TYPE string,
l_tabellenname(10) TYPE c,
l_arbeitsbereichsname(10) TYPE c,
h_string TYPE string,
h_char(255) TYPE c.
FIELD-SYMBOLS: <l_tabelle> TYPE ANY TABLE,
<l_arbeits> TYPE ANY,
<feldzeiger> TYPE ANY.
CLEAR strtab.
CONCATENATE 'IT_' ittab INTO l_tabellenname.
ASSIGN (l_tabellenname) TO <l_tabelle>.
CONCATENATE 'WA_' ittab INTO l_arbeitsbereichsname.
ASSIGN (l_arbeitsbereichsname) TO <l_arbeits>.
LOOP AT <l_tabelle> INTO <l_arbeits>.
CLEAR: h_zaehler, line_str.
line_str = ittab.
DO.
ADD 1 TO h_zaehler.
ASSIGN COMPONENT h_zaehler OF
STRUCTURE <l_arbeits> TO <feldzeiger>.
IF sy-subrc <> 0. EXIT. ENDIF.
WRITE <feldzeiger> TO h_char LEFT-JUSTIFIED. "#EC *
h_string = h_char.
CONCATENATE line_str separator h_string INTO line_str.
ENDDO.
APPEND line_str TO strtab.
ENDLOOP.
ENDFORM. "data_to_string
Maybe you are looking for
-
Prep for Migration from PC to Mac (Ext Drive)
I plan to purchase a Mac desktop in a few months. I need to backup my PC files (cause I never have!) and create some hard drive space on my sluggish PC. Can I do the following: 1) Use an external hard drive and back-up all files 2) Upon Mac purchase,
-
Macbook pro 15" late 2011ram upgrade
Hello, i have a macbook pro 15" late 2011 which came with 4gb ram and am thinking of upgrading with this http://www.crucial.com/ProductDisplay?urlRequestType=Base&catalogId=10151&catego ryId=&productId=11645&urlLangId=-1&langI- or this http://www.cor
-
Cannot close attachment in mail
I received an invoice PDF. I opened it. Now when I open email, I only see the PDF not my accounts let alone my email. How do I close THE PDF? Pinch gesture closes entire email program app, when I open email app there is THE PDF again.
-
After a recent firmware update, my Mac Mini will not startup with the HDMI cable plugged in. It beeps three times at startup and won't boot. If I unplug the HDMI cable it starts up just fine and then I can plug in the HDMI and get the screen working.
-
How to install drivers for windows 7 from bootcamp
how to install bluetooth driver for windows 7 (bootcamp)?