Query based on a date range
I want to query based on a date range. I wrote the following EJB QL:
"select object(a) from ActionItems as a where a.dueDate
between ?1 and ?2"
But when I deployed the application to Oracle's EJB server, I got the following error:
Auto-deploying biogen.jar (No previous deployment found)... Invalid type for expression (a.dueDate BETWEEN ?1 AND ?2)
EJB QL statement : 'select object(a) from ActionItems as a where a.dueDate between ?1 and ?2'
EJB QL method : public abstract java.util.Collection ActionItemsLocalHome.findByDueDateRange(java.sql.Date,java.sql.Date) throws javax.ejb.FinderException
at com.sun.ejb.ejbql.parser.EjbQLParser.parse EjbQLParser.java:218)
at com.sun.ejb.ejbql.EjbQLDriver.parse(EjbQLDriver.java:86)
at com.sun.ejb.sqlgen.SQLGenerator.generateSQLForEjbQLQueries(SQLGenerator.java:704)
It works fine for a number range, but does not work for a date range.
Any one has an idea on how to write a correct EJB QL for a query based on date range?
Thanks.
Jingzhi
Re-posted. Please help!
Similar Messages
-
Creation of internal table dynamically based on the Date Range entered
Hi SAPgurus,
I have been facing one issue i.e creation of internal table dynamically based on the date range entered in the selection screen. For example the date range I am giving as 06/2006 to 08/2006, it should display the Fieldcatelog dynamically, this part i have completed but the only issue I am facing is to populate the sales data into that fields.
Right now my program is displaying the ALV like this.
Ex:
<b>CSR District 06/2006 07/2006 08/2006 totals</b>
Shiva New York 10.00
Shiva new york 30.00
Shiva new york 40.00
but it should display like this
<b>CSR District 06/2006 07/2006 08/2006 totals</b>
Shiva New York 10.00 30.00 40.00
80.00
Please help me in this scenario, how to acheive like this..
Thanks & Regards,
Sivaram KandulaHi Sivaram,
I also got the same requirement . i saw rich and your code whatever you have uploaded.i have created dynamic internal table but i am facing the issue to populating the data to my dynamic internal table.
Sivaram, can you please explain your code after this.
*<dyn_table>
*tab_item.
LOOP AT tab_item.
ASSIGN COMPONENT 1 OF STRUCTURE <dyn_wa> TO <dyn_table>.
ASSIGN COMPONENT 2 OF STRUCTURE <dyn_wa> TO <dyn_table>.
* <dyn_wa> = tab_item-bztxt.
* <dyn_wa> = tab_item-total.
* APPEND <dyn_wa> TO <dyn_table>.
** <dyn_wa> = tab_item-total.
** ASSIGN tab_item-bezei TO <dyn_wa>.
* APPEND <dyn_table>.
ENDLOOP.
how you are puting the loop at tab_item. but tab_item is already commented.
can you send me the code after that.
i am sending some part of my code.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fCAT1
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <dyn_table>.
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
select vbeln
fkart
vkorg
vtweg
fkdat
spart
fksto
from vbrk
client specified
into table gt_vbrk
where mandt = sy-mandt
and fkart in ('ZF5','ZFR')
and vkorg = '1100'
and vtweg = '20'
and fkdat in s_fkdat
and spart = '06'
and fksto = ' '.
if gt_vbrk[] is not initial.
select vbeln
fkimg
prsdt
netwr
matnr
arktx
werks
mwsbp
from vbrp
client specified
into table gt_vbrp
for all entries in gt_vbrk
where vbeln = gt_vbrk-vbeln
and werks in s_werks
and matnr in s_matnr.
endif.
select mnr ltx spras from t247
into table it_t247
where spras = 'E'.
data: lv_month1 type vbrp-prsdt,
name1(3) type c,
s_month type string,
s_month1 type string,
s_month2 type string.
* lv_netwr1 type vbrp-netwr,
* lv_mwsbp1 type vbrp-mwsbp.
loop at gt_vbrp into gs_vbrp.
gs_final2-matnr = gs_vbrp-matnr.
gs_final2-arktx = gs_vbrp-arktx.
gs_final2-fkimg = gs_vbrp-fkimg.
lv_month1 = gs_vbrp-prsdt.
read table it_t247 into wa_t247 with key mnr = lv_month1+4(2).
if sy-subrc eq 0.
name1 = wa_t247-ltx.
endif.
concatenate name1
lv_month1(4) into s_month SEPARATED BY '_' .
CONCATENATE S_MONTH 'QTY' INTO S_MONTH1 SEPARATED BY ''.
CONCATENATE S_MONTH 'VALUE' INTO S_MONTH2 SEPARATED BY ''.
gs_final2-month = s_month.
lv_netwr1 = gs_vbrp-netwr.
lv_mwsbp1 = gs_vbrp-mwsbp.
gs_final2-MONTH_QTY = S_MONTH1.
GS_FINAL2-MONTH_VAL = S_MONTH2.
gs_final2-value = lv_netwr1 + lv_mwsbp1.
append gs_final2 to gt_final2.
clear: gs_final2. "lv_name2.
endloop.
if gt_final2[] is not initial.
sort gt_final2 by matnr month ascending .
loop at gt_final2 into gs_final2.
gs_final2_01 = gs_final2.
collect gs_final2_01 into gt_final2_01.
endloop.
endif.
ENDIF..
Regards
Ankur -
Query output based on the date range ...
Hi All,
I have an issue related to the jump query, main query based on the time frame. For Example if he selects Sold_To : 6895 for the Calday 10/01/2007 01/31/2008 and when jumps to jump query , the jump query should display the data based on the input given in the main query. That is it should show the data individually for four months.
Expecting the reply from your side...
Thanks in advance
Regards,
SruthiSruthi,
Make sure that u have those 3 fields in 2nd Query and CALDAY with Variable.
Create settings in RSBBS.
Click on ASSIGNMENT DETAILS tab
CALDAY > Type = Variable > Selection Type = Selection/Single value/Multiple single values ( same like ur first query )
All other fields ( 3 na ) > Type = Generic
Click on Continue / Save.
If you need more info...if possible come to yahoo chat my ID is [email protected]....and am online now.
Regards,
Ramkumar. -
MDM ABAP API query to pass the date range
Hi
I want to retrieve certain data from MDM repository based on filter criteria by date stamp.
Not sure how to do it to pass the select option value in the query.
select-options: s_cdate for sy-datum obligatory .
DATA wa_query TYPE mdm_query.
DATA: v_search_date1 TYPE MDM_CDT_DATE_TIME.
data: v_datestamplow1 type string.
data: v_datestamplow type TZNTSTMPL.
concatenate s_cdate-low '000000' into v_datestamplow1
v_datestamplow = v_datestamplow1.
clear wa_query.
wa_query-parameter_code = 'Changed_On '. "Field code ( Field name )
wa_query-operator = 'EQ'.
wa_query-dimension_type = mdmif_search_dim_field. "Field search
wa_query-constraint_type = MDMIF_SEARCH_CONSTR_DATE. "Date serach
I am able to get the data when I just pass the low value from selecct option. But I dont how to pass the date range.
v_search_date1-CONTENT = v_datestamplow.
ET REFERENCE OF v_search_date1 INTO wa_query-value_low.
APPEND wa_query TO gt_query.
CALL METHOD cl_api->mo_core_service->query
EXPORTING
iv_object_type_code = 'Vendors'
it_query = gt_query
IMPORTING
et_result_set = gt_result.
II could see the below operator types . Although EQ says "Like standard select-options parameter" not sure how to pass the value.
EQ Equal to (like standard select-options parameter)
NE Not equal to (like standard select-options parameter)
LT Less than (like standard select-options parameter)
LE Less than or equal to (like standard s-o parameter)
GT Greater than (like standard select-options parameter)
GE Greater than or equal to (like standard s-o parameter
SW Starts with (MDM specific parameter)
Thanks,
Krishna.Hi,
To get the date range for select options, pass the low value with 'GE' operator and another query option with 'LE' operator for high value.
select-options: s_cdate for sy-datum obligatory .
DATA wa_query TYPE mdm_query.
DATA: v_search_date1 TYPE MDM_CDT_DATE_TIME.
data: v_datestamplow1 type string.
data: v_datestamplow type TZNTSTMPL.
concatenate s_cdate-low '000000' into v_datestamplow1
v_datestamplow = v_datestamplow1.
clear wa_query.
wa_query-parameter_code = 'Changed_On '. "Field code ( Field name )
wa_query-operator = 'GE'.
wa_query-dimension_type = mdmif_search_dim_field. "Field search
wa_query-constraint_type = MDMIF_SEARCH_CONSTR_DATE. "Date serach
GET REFERENCE OF v_search_date1 INTO wa_query-value_low.
APPEND wa_query TO gt_query.
concatenate s_cdate-high '235959' into v_datestamphigh1
v_search_date2 = v_datestamphigh1.
clear wa_query.
wa_query-parameter_code = 'Changed_On '. "Field code ( Field name )
wa_query-operator = 'LE'.
wa_query-dimension_type = mdmif_search_dim_field. "Field search
wa_query-constraint_type = MDMIF_SEARCH_CONSTR_DATE. "Date serach
GET REFERENCE OF v_search_date2 INTO wa_query-value_low.
APPEND wa_query TO gt_query.
CALL METHOD cl_api->mo_core_service->query
EXPORTING
iv_object_type_code = 'Vendors'
it_query = gt_query
IMPORTING
et_result_set = gt_result.
Thanks. -
Metrics generation based on (birth) date ranges
Hello all,
Am a beginner in OBIEE. Am trying to derive some metrics out of birthdate information I have. Its a 2 part question.
1) Count of occurrence of birthdates.
Its a simple count(*) query and this I was able to get it done in OBIEE - all the formatting is done
Eg:
source data
*19300203*
*19300203*
*18301203*
*19600204*
metrics out of that
*19300203 - 2*
*18301203 - 1*
*19600204 - 1*
2) Count of birthdate based on period distribution.
Now, categorizing the date range in to 3 distributions.
a) before 1900
b) 1900 to 1950
c) after 1950
output will should be something like -
before 1900 - 1
*1900 to 1950 - 2*
after 1950 - 1
I tried a lot and searched in forums and now stuck really and could not proceed with this type of data generation model.
Can you please show some pointers on how I can proceed with this?
Many thanks.Hi,
Bit tricky without more details of your model, but im guessing you have a date dimension and a fact with your count measure.
I'd start in answers, create some 'Bins' on your date column or manually write a case statement to create the attribute you want to group the counts by (ie :
when date < 1900 then 'Before 1900' else when < 1951 then '1900 to 1950' else 'after 1950)
If your happy with this result, I'd move the case statement back into the RPD BMM layer as a logical column in your Date dimension and go from there. This way the grouping of dates is available across other reports and is not confined to a specific formula in the report you are currently working on.
HTH, let us know if you get stuck. -
Hello Experts,
Is there a function module to get the sales orders from CRM based on a given date range which
is for the field created_at? Also, is the field OBJECTID in table CRMD_ORDERADM_H can
be compared against VBAK-VBELN? Thank you guys and take care!Hi,
You can create your own function module for this. You can fetch sales order from table crmd_orderadm_h, put input data as date, and two conditions for sales order should be object type = 'BUS2000115' and PROCESS TYPE = 'TA' if you are looking for standard order.
You have to fetch object id from this table to get your order number.
Thanks,
Shweta
Message was edited by:
Shweta Verma -
Add a flag column in the Query based on Cancel date
hi Guys,
I have a Characterstic object 0canceldate and it gets the cancellation date of the sales order. Based on that date i need to add a column in the report like if 0canceldate has ahappened or populate then show Yes or No in the coumn like a flag.
Can anybody help me how i can do that?SELECT d.NAME
FROM
(SELECT jta.NAME
FROM apps.jtf_terr_values_all jtva,
apps.jtf_terr_qual_all jtqa,
apps.jtf_terr_all jta ,
apps.hz_party_sites ps,
apps.hz_locations hl
WHERE jtva.terr_qual_id = jtqa.terr_qual_id
AND jtqa.terr_id = jta.terr_id
AND jtva.low_value_char = hl.postal_code
AND jtqa.org_id = jtva.org_id
AND jta.org_id = jtqa.org_id
AND ps.location_id = hl.location_id
AND hl.country in( 'CA', 'US')) D;
UNION
SELECT jta.NAME
FROM apps.jtf_terr_values_all jtva,
apps.jtf_terr_qual_all jtqa,
apps.jtf_terr_all jta,
apps.hz_party_sites ps,
apps.hz_locations hl
WHERE jtva.terr_qual_id = jtqa.terr_qual_id
AND jtqa.terr_id = jta.terr_id
AND ps.location_id = hl.location_id
AND jtqa.org_id = jtva.org_id
AND jta.org_id = jtqa.org_id
AND hl.country = 'US'
AND hl.postal_code BETWEEN jtva.low_value_char AND jtva.high_value_char
)d; -
Query using Between for date range
Hi,
I need to list a date range of registration.. i entered
4/12/2007 (as value for form.regstart) and 7/12/2007 (as value for
form.regend)..
WHERE dateregistered BETWEEN #CreateODBCDate(form.regstart)#
AND #CreateODBCDate(form.regend)#
the result that i got was only from 4/12/2007 to 6/7/2007..
however when i run the same coding at mysql.. it works
perfectly..
any idea?Turn on debugging and see what dates show up in the sql that
went to your db. Cold Fusion might be confused by your date format.
I certainly am. -
Query to get values based on a date range.
11g.
Hi there,
I have a simple requirement(hopefully).
I have a parameter which is basically a count range which when I pass the sql query should fetch the values from a column falling in that range.
My table is item details
Item cost
item1 1
item2 10
item3 20
item4 3
.I have a parameter which I have to pass to this query where items are listed based on the cost.
So I want to select items which cost between 0 -10, 11-20, 21-30 and 31-40
Now I am using Apex to show the count report like
0-10 11- 20 21- 30 31- 40
3 2 0 0
The numbers are hyperlinked and I pass the parameters based on which another report shows the details. So if the user clicks on number 3 in the report. The underlying query would be something like
select * from item_Details where cost between 0 and 10.So I was wondering how do pass the parameter to the sql in the best possible way to get the costs based on the range?
Maybe the parameters should be some code which can be decoded in the SQL?
Any help or suggestions please?
Thanks,
RyanHi,
Try this to pass the parameter in the query...
select * from item_Details where cost between to_number(substr('0-10',0,instr('0-10','-')-1)) and to_number(substr('0-10',instr('0-10','-')+1,length('0-10'));
Regards,
Niha -
Hi,
I am trying to archive files from a SharePoint 2010 document library by moving them to another library that's a dedicated archive/folder/library. The files to be moved are selected based on their modified date column value that should range between any time
in the past to January 1st 2012.
Also, to be able to retain the tags and cloumn values after the move. Open in explorer does not bring along the user added tags.
I tried to edit this script
$WebURL = "http://mysite.com/";
$ListDisplayName = "Crawl Test Library";
$ArchiveFolderName = "Crawl Test Library Archive";
function moveItems ()
trap
#make sure we dispose of these in the event of an error to avoid memory leaks:
write-host "Error - disposing of objects...";
$Web.Dispose();
$Site.Dispose();
[Microsoft.SharePoint.SPSite] $Site = New-Object Microsoft.SharePoint.SPSite($WebURL);
[Microsoft.SharePoint.SPWeb] $Web = $Site.OpenWeb();
[Microsoft.SharePoint.SPList] $List = $Web.Lists[$ListDisplayName];
$FolderToMoveTo = $List.RootFolder.Url + "/" + $FolderName;
$ItemMoveCount=0;
$Query = New-Object Microsoft.SharePoint.SPQuery;
$Query.Folder = $list.RootFolder;
$camlQuery = "<Where><Leq><FieldRef Name='Modified' /><Value Type='DateTime'>2012-01-01T00:00:00Z</Value></Leq></Where>"
$Query.Query = $camlQuery
$Query.RowLimit = 2200; #limit query because of large folder
$List.GetItems($Query) |
Where {$_.ContentType.Name -ne "Folder"} |
foreach-object {
#Line below will simply output to console and demonstrates another .NET call
[System.String]::format("Moving Item {0} with ID {1}...",$_.Name, $_.ID.ToString());
$Web.GetFile($_.Url).MoveTo([System.String]::format("{0}/{1}",$FolderToMoveTo,$_.Name));
write-host "Success...";
$ItemMoveCount++;
write-host "==============================================================================";
write-host "Complete! -> Moved " $ItemMoveCount " Items to directory " $FolderName;
write-host "==============================================================================";
#dispose:
$Web.Dispose();
$Site.Dispose();
#garbage collection
[GC]::Collect()
to do that but it doesn't seem to work. I am no guru in powershell yet so any help is appreciated.
Thanks.This solution gets the job done. Much thanks to
Ian Hayse
NB...The Modified and Created dates are gonna reflect runtime dates now
$web = Get-SPWeb "http://sharepointed.com/"
$list = $web.Lists["Shared Documents"]
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.RowLimit = 2000
$caml = '<Where><Lt><FieldRef Name="Created" /><Value IncludeTimeValue="TRUE" Type="DateTime">2014-01-01T04:06:45Z</Value></Lt></Where> '
$spQuery.Query = $caml
do
$listItems = $list.GetItems($spQuery)
$spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
$listTotal = $listItems.Count
for ($x=$listTotal-1;$x -ge 0; $x--)
try
$listItems[$x].CopyTo("http://sharepoint/Docs/Documents/"+ $listItems[$x].name)
Write-Host("DELETED: " + $listItems[$x].name)
$listItems[$x].Recycle()
catch
Write-Host $_.Exception.ToString()
while ($spQuery.ListItemCollectionPosition -ne $null) -
How can I make CONTAINS query work for a date range
In either 9i or 10g (eventual). I have a CONTEXT index that contains multiple columns from multiple tables and using a USER_DATASTORE. E.g., I have names that come from 3 different table locations and dates that come from 4. I can index them fine but how can I perform a single consolidated CONTAINS query against the single CONTEXT index to do the following:
smith WITHIN lname AND john WITHIN fname AND dob BETWEEN '19870315' and '19970315'
I know that I can use a mixed query but this is inefficient (esp since I have birth dates in multiple tables). Is there any algorithm for a range operator (>, <, between?) within the CONTAINS operator?
CTXCAT index is not an option, as I have many text columns I am searching.
Thanks!When you run the cdstore.sql, in addition to creating the ctx_cd package, it also creates the friedman package that contains the algorithm that the ctx_cd package uses. You could use the functions from that friedman package in your procedure for your user_datastore and in the creation of your query string, as demonstrated below.
SCOTT@orcl_11g> CREATE OR REPLACE PROCEDURE my_proc
2 (p_rowid IN ROWID,
3 p_clob IN OUT NOCOPY CLOB)
4 AS
5 BEGIN
6 FOR r IN
7 (SELECT emp.ename, emp.job, emp.hiredate, dept.dname
8 FROM emp, dept
9 WHERE emp.deptno = dept.deptno
10 AND emp.ROWID = p_rowid)
11 LOOP
12 DBMS_LOB.WRITEAPPEND (p_clob, 7, '<ename>');
13 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r.ename), r.ename);
14 DBMS_LOB.WRITEAPPEND (p_clob, 8, '</ename>');
15 DBMS_LOB.WRITEAPPEND (p_clob, 5, '<job>');
16 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r.job), r.job);
17 DBMS_LOB.WRITEAPPEND (p_clob, 6, '</job>');
18 DBMS_LOB.WRITEAPPEND (p_clob, 7, '<dname>');
19 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r.dname), r.dname);
20 DBMS_LOB.WRITEAPPEND (p_clob, 8, '</dname>');
21 DBMS_LOB.WRITEAPPEND (p_clob, 10, '<hiredate>');
22 -- apply friedman algorithm to date column ------------------
23 friedman.init
24 (TO_NUMBER (TO_CHAR (TO_DATE (19000101, 'YYYYMMDD'), 'J')),
25 TO_NUMBER (TO_CHAR (TO_DATE (21001231, 'YYYYMMDD'), 'J')));
26 DBMS_LOB.WRITEAPPEND
27 (p_clob,
28 LENGTH (friedman.encodedate (r.hiredate)),
29 friedman.encodedate (r.hiredate));
30 --------------------------------------------------------------
31 DBMS_LOB.WRITEAPPEND (p_clob, 11, '</hiredate>');
32 END LOOP;
33 END my_proc;
34 /
Procedure created.
SCOTT@orcl_11g> SHOW ERRORS
No errors.
SCOTT@orcl_11g> BEGIN
2 CTX_DDL.CREATE_PREFERENCE ('my_datastore', 'USER_DATASTORE');
3 CTX_DDL.SET_ATTRIBUTE ('my_datastore', 'PROCEDURE', 'my_proc');
4 END;
5 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11g> CREATE INDEX my_index ON emp (ename)
2 INDEXTYPE IS CTXSYS.CONTEXT
3 PARAMETERS
4 ('DATASTORE my_datastore
5 SECTION GROUP CTXSYS.AUTO_SECTION_GROUP')
6 /
Index created.
SCOTT@orcl_11g> EXEC DBMS_STATS.GATHER_TABLE_STATS (USER, 'DEPT')
PL/SQL procedure successfully completed.
SCOTT@orcl_11g> EXEC DBMS_STATS.GATHER_TABLE_STATS (USER, 'EMP')
PL/SQL procedure successfully completed.
SCOTT@orcl_11g> VARIABLE cstring VARCHAR2(4000)
SCOTT@orcl_11g> BEGIN
2 :cstring := 'smith WITHIN ename';
3 :cstring := :cstring || ' AND ' || 'clerk WITHIN job';
4 :cstring := :cstring || ' AND ' || 'research WITHIN dname';
5 -- apply friedman algorithm to search criteria ---------------------------
6 friedman.init
7 (TO_NUMBER (TO_CHAR (TO_DATE (19000101, 'YYYYMMDD'), 'J')),
8 TO_NUMBER (TO_CHAR (TO_DATE (21001231, 'YYYYMMDD'), 'J')));
9 :cstring := :cstring || ' AND ((' ||
10 friedman.integercontainscriteria
11 (TO_NUMBER (TO_CHAR (TO_DATE ('19800315', 'YYYYMMDD'), 'J')),
12 TO_NUMBER (TO_CHAR (TO_DATE ('19810315', 'YYYYMMDD'), 'J')),
13 'B')
14 || ') WITHIN hiredate)';
15 ---------------------------------------------------------------------------
16 END;
17 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11g> SET AUTOTRACE ON EXPLAIN
SCOTT@orcl_11g> SELECT *
2 FROM emp
3 WHERE CONTAINS (ename, :cstring) > 0
4 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
Execution Plan
Plan hash value: 1887222286
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 37 | 4 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 37 | 4 (0)| 00:00:01 |
|* 2 | DOMAIN INDEX | MY_INDEX | | | 4 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("CTXSYS"."CONTAINS"("ENAME",:CSTRING)>0)
SCOTT@orcl_11g> -
Poor query performance when using date range
Hello,
We have the following ABAP code:
select sptag werks vkorg vtweg spart kunnr matnr periv volum_01 voleh
into table tab_aux
from s911
where vkorg in c_vkorg
and werks in c_werks
and sptag in c_sptag
and matnr in c_matnr
that is translated to the following Oracle query:
SELECT
"SPTAG" , "WERKS" , "VKORG" , "VTWEG" , "SPART" , "KUNNR" , "MATNR" , "PERIV" , "VOLUM_01" ,"VOLEH" FROM SAPR3."S911" WHERE "MANDT" = '003' AND "VKORG" = 'D004' AND "SPTAG" BETWEEN 20101201 AND 20101231 AND "MATNR" BETWEEN 000000000100000000 AND 000000000999999999;
Because the field SPTAG is not enclosed by apostropher, the oracle query has a very bad performance. Below the execution plans and its costs, with and without the apostrophes. Please help me understanding why I am getting this behaviour.
##WITH APOSTROPHES
SQL> EXPLAIN PLAN FOR
2 SELECT
3 "SPTAG" , "WERKS" , "VKORG" , "VTWEG" , "SPART" , "KUNNR" , "MATNR" , "PERIV" , "VOLUM_01" ,"VOLEH" FROM SAPR3."S911" WHERE "MANDT" = '003' AND "VKORG" = 'D004' AND "SPTAG" BETWEEN '20101201' AND '20101231' AND "MATNR" BETWEEN '000000000100000000' AND '000000000999999999';
Explained.
SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());
PLAN_TABLE_OUTPUT
Id
Operation
Name
Rows
Bytes
Cost (%CPU)
0
SELECT STATEMENT
932
62444
150 (1)
1
TABLE ACCESS BY INDEX ROWID
S911
932
62444
149 (0)
2
INDEX RANGE SCAN
S911~VAC
55M
5 (0)
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
1 - filter("VKORG"='D004' AND "SPTAG">='20101201' AND
"SPTAG"<='20101231')
2 - access("MANDT"='003' AND "MATNR">='000000000100000000' AND
"MATNR"<='000000000999999999')
##WITHOUT APOSTROPHES
SQL> EXPLAIN PLAN FOR
2 SELECT
3 "SPTAG" , "WERKS" , "VKORG" , "VTWEG" , "SPART" , "KUNNR" , "MATNR" , "PERIV" , "VOLUM_01" ,"VOLEH" FROM SAPR3."S911" WHERE "MANDT" = '003' AND "VKORG" = 'D004' AND "SPTAG" BETWEEN 20101201 AND 20101231 AND "MATNR" BETWEEN '000000000100000000' AND '000000000999999999';
SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());
Explained.
SQL>
PLAN_TABLE_OUTPUT
Id
Operation
Name
Rows
Bytes
Cost (%CPU)
0
SELECT STATEMENT
2334
152K
150 (1)
1
TABLE ACCESS BY INDEX ROWID
S911
2334
152K
149 (0)
2
INDEX RANGE SCAN
S911~VAC
55M
5 (0)
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
1 - filter("VKORG"='D004' AND TO_NUMBER("SPTAG")>=20101201 AND
TO_NUMBER("SPTAG")<=20101231)
2 - access("MANDT"='003' AND "MATNR">='000000000100000000' AND
"MATNR"<='000000000999999999')
Best Regards,
Daniel G.Volker,
Answering your question, regarding the explain from ST05. As a quick work around I created an index (S911~Z9), but still I'd like to solve this issue without this extra index, as primary index would work ok, as long as date was correctly sent to oracle as string and not as number.
SELECT
"SPTAG" , "WERKS" , "VKORG" , "VTWEG" , "SPART" , "KUNNR" , "MATNR" ,
"PERIV" , "VOLUM_01" , "VOLEH"
FROM
"S911"
WHERE
"MANDT" = :A0 AND "VKORG" = :A1 AND "SPTAG" BETWEEN :A2 AND :A3 AND "MATNR"
BETWEEN :A4 AND :A5
A0(CH,3) = 003
A1(CH,4) = D004
A2(NU,8) = 20101201 (NU means number correct?)
A3(NU,8) = 20101231
A4(CH,18) = 000000000100000000
A5(CH,18) = 000000000999999999
SELECT STATEMENT ( Estimated Costs = 10 , Estimated #Rows = 6 )
5 3 FILTER
Filter Predicates
5 2 TABLE ACCESS BY INDEX ROWID S911
( Estim. Costs = 10 , Estim. #Rows = 6 )
Estim. CPU-Costs = 247.566 Estim. IO-Costs = 10
1 INDEX RANGE SCAN S911~Z9
( Estim. Costs = 7 , Estim. #Rows = 20 )
Search Columns: 4
Estim. CPU-Costs = 223.202 Estim. IO-Costs = 7
Access Predicates Filter Predicates
The table originally includes the following indexes:
###S911~0
MANDT
SSOUR
VRSIO
SPMON
SPTAG
SPWOC
SPBUP
VKORG
VTWEG
SPART
VKBUR
VKGRP
KONDA
KUNNR
WERKS
MATNR
###S911~VAC
MANDT
MATNR
Number of entries: 61.303.517
DISTINCT VKORG: 65
DISTINCT SPTAG: 3107
DISTINCT MATNR: 2939 -
Want to select query based on sample data.
My Oracle Version
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
I am creating inventory valuation report using FIFO method . here sample data .
create table tranx(
TRXTYPE varchar2(10) ,ITEM_CODE varchar2(10), RATE number,qty number
insert into tranx values('IN' ,'14042014', 457.2 ,10);
insert into tranx values('OUT','14042014', 0, 10);
insert into tranx values('IN','14042014', 458.1, 35);
insert into tranx values('OUT','14042014', 0, 11);
insert into tranx values('OUT','14042014', 0, 6);
insert into tranx values('IN',' 14042014', 457.2 ,10);
insert into tranx values('OUT',' 14042014', 0, 3);
insert into tranx values('OUT',' 14042014', 0, 4);
insert into tranx values('IN',' 14042014', 457.2, 20);
insert into tranx values('OUT',' 14042014', 0, 5);
insert into tranx values('OUT',' 14042014', 0, 9);
insert into tranx values('OUT',' 14042014', 0, 8);
current output
TRXTYPE ITEM_CODE RATE QTY
IN 14042014 457.2 10
OUT 14042014 0 10
IN 14042014 458.1 35
OUT 14042014 0 11
OUT 14042014 0 6
IN 14042014 457.2 10
OUT 14042014 0 3
OUT 14042014 0 4
IN 14042014 457.2 20
OUT 14042014 0 5
OUT 14042014 0 9
OUT 14042014 0 8above data populate based on first in first out . but out rate is not comes from that query. suppose fist 10 qty are OUT its rate same as IN. but when qty start out from 35 rate will be 458.1 till all 35 qty will not out. like out qty 11,6,3,4,5,9 now total are 38 .
when qty 9 will out the rate are 6 qty rate 458.1 and other 3 out rate of 457.2 means total value of 9 out qty value is 4120.20 .
Now 35 qty is completed and after that rate will continue with 457.2 till 10 qty not completed.
I think you understand my detail if not please tell me .
thanks
i am waiting your reply.As SomeoneElse mentioned, there is no row order in relational tables, so you can't tell which row is first and which is next unless ORDER BY is used. So I added column SEQ to your table:
SQL> select *
2 from tranx
3 /
TRXTYPE ITEM_CODE RATE QTY SEQ
IN 14042014 457.2 10 1
OUT 14042014 0 10 2
IN 14042014 458.1 35 3
OUT 14042014 0 11 4
OUT 14042014 0 6 5
IN 14042014 457.2 10 6
OUT 14042014 0 3 7
OUT 14042014 0 4 8
IN 14042014 457.2 20 9
OUT 14042014 0 5 10
OUT 14042014 0 9 11
TRXTYPE ITEM_CODE RATE QTY SEQ
OUT 14042014 0 8 12
12 rows selected.
SQL> Now it can be solved. Your task requires either hierarchical or recursive solution. Below is recursive solution using MODEL:
with t as (
select tranx.*,
case trxtype
when 'IN' then row_number() over(partition by item_code,trxtype order by seq)
else 0
end rn_in,
case trxtype
when 'OUT' then row_number() over(partition by item_code,trxtype order by seq)
else 0
end rn_out,
count(case trxtype when 'OUT' then 1 end) over(partition by item_code) cnt_out
from tranx
select trxtype,
item_code,
rate,
qty
from t
model
partition by(item_code)
dimension by(rn_in,rn_out)
measures(trxtype,rate,qty,qty qty_remainder,cnt_out,1 current_in,seq)
rules iterate(10) until(iteration_number + 1 = cnt_out[0,1])
rate[0,iteration_number + 1] = rate[current_in[1,0],0],
qty_remainder[0,iteration_number + 1] = case sign(qty_remainder[0,cv() - 1])
when 1 then qty_remainder[0,cv() - 1] - qty[0,cv()]
else qty[current_in[1,0],0] - qty[0,cv()] + nvl(qty_remainder[0,cv() - 1],0)
end,
current_in[1,0] = case sign(qty_remainder[0,iteration_number + 1])
when 1 then current_in[1,0]
else current_in[1,0] + 1
end
order by seq
TRXTYPE ITEM_CODE RATE QTY
IN 14042014 457.2 10
OUT 14042014 457.2 10
IN 14042014 458.1 35
OUT 14042014 458.1 11
OUT 14042014 458.1 6
IN 14042014 457.2 10
OUT 14042014 458.1 3
OUT 14042014 458.1 4
IN 14042014 457.2 20
OUT 14042014 458.1 5
OUT 14042014 458.1 9
TRXTYPE ITEM_CODE RATE QTY
OUT 14042014 457.2 8
12 rows selected.
SQL> SY. -
"Export to Excel" does not work for query based on Master Data InfoSet
We have many queries based on InfoSet consisting 2 or more PS Master Data. After we upgraded from BW 3.1 to 3.5, the "Export To Excel" function no longer works via BEx Browser. It returns all blanks where master data should be shown. Only the non-data area like column headings are exported to excel.
Is this a bug introduced in BW 3.5?
Thanks,
KinukoIt seems that BW 3.5 SP10 may fix this problem.
-
A/r Invoice report query based on posting date selection criteria
Hi experts,
I am trying to write a query to get the A/r invoice report including Docnum, Docdate, cardname, project, linetotal, taxcode, taxtotal.
and i tried the below query
SELECT T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName],T1.[LineTotal] FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocDate] >=[%0] AND T0.[DocDate] <=[%1]
In this query ,
1) i am unable to sum up the linetotal( total before tax)
2) also unable to fetch the sum of taxamount.
3) its more important , the above query will me docnum , when i try to open that doc, it opens the 2007 docments. whereas the other details are correct like docdate, amount and all.
example: from date: 1/04/2011 to date: 28/07/2011
Docnum Docdate cardname linetotal.... etc
2 1/04/11 XYZ 5000
when i click the 2 (docnum) it opens me the 04/04/2007 documents.
how to limit the doc within the periods given?
thanks in advance
DwarakHi Rahul/Gordon,
thanks for your query's .
additionally, i want this query without the A/r invoices whichever having credit memo as target doc.
and
i have selection criteria as T0.[U_Sec_Category] = '[%2]' and this has 3 values like 1)CIM 2)BIN 3)DMP
among these CIM should be seen only only user1 and BIN & DMP only by user2.
can u plz get me this
thanks,
Dwarak
Maybe you are looking for
-
Can iTunes sync multiple songs with the same name?
My iTunes library has multiple songs with the same name (but they point to different files on the filesystem). Curiously when iTunes syncs to my iPhone it will only ever sync two of the files, even if more exists. I suspect what is happening is descr
-
Older version files, can't open
I created interactive vidoes with Micromedia Director, 2007. The new Adobe director no longer recognizes/accepts these files. When looking for older versions to download, my Mac's most recent operating system will no longer support the files either.
-
Is there a way to pull images from an slideshow?
how do i pull images from a slideshow and bring them back to normal iphoto album?
-
Will windows xp install in bootcamp on a iMac running lion?
I just ordered a new iMac and would like to install windows xp on the machine when I receive it. It is my understanding that lion will only support windows 7 and not xp in boot camp. The old pc programs I have need to run on xp. Am I in trouble?
-
How to turn broadcast SSID on/off
EA3500, I'm using the Smart Wi-Fi interface through a browser. How do I make my router broadcast the SSID? I think it was when I was setting up using the old interface, before updating the firmware, that I set it to *not* broadcast the network name.