Add a parameter in the where clause in mdx
I need check for a value from a Dimension and filter in the MDX Query as below...
select {[Measures].[AMOUNT]} ON COLUMNS,
{([Organisation Structure].[ALL Organisation Structures], [Account Detail].[ALL Account Details], [Monthly Calendar].[ALL Monthly Calendars])} ON ROWS
from [Annu]
where Filter([useridentity].[All Users].Children, (InStr([useridentity].[All Users].CurrentMember.Properties("Caption"), "14,1") > 0.0))
From the above query, we are checking if the ALL Users value is 14,1 then it is filtering but I want to pass the value as parameter something like where Filter([useridentity].[All Users].Children, (InStr([useridentity].[All Users].CurrentMember.Properties("Caption"),
@value) > 0.0)) and @value should be assigned the values from one of the dimensional attributes..
Thanks in advance...
RamarajuC
Hi Ramaraju ,
I am adding an example on AW to make it easier to solve your problem .. Please notice the @datasrc you need to insert, all the quote marks and the strtomember function in case you need to ..
EXEC sp_addlinkedserver
@server='OLAP_LINKED',
@srvproduct='',
@provider='MSOLAP.4', -- For SQLServer 2008 R2
@datasrc='YourServarName', -- Can be localhost if you're working on the server
@catalog='Adventure Works DW 2008R2 SE'
declare @EPN varchar(100)
declare @sql varchar(2000)
set @EPN = '[Ship Date].[Fiscal].[Fiscal Year].&[2008]'
set @sql = 'SELECT * FROM OPENQUERY(OLAP_LINKED,''Select {[Measures].[Internet Sales Amount] } on columns, {[Product].[Product Categories].[All Products]} on rows from [Adventure Works] where STRTOMEMBER('''''+@EPN+''''') '')'
EXEC (@sql)
I hope we are on our way toward the solution :)
Regards, David .
Similar Messages
-
Parsing an input parameter for the where clause or record select value
In my limited CR experience, I've always used a command database connection so that I can write my own SQL. However, now I have to parse a pipe delimited parameter to get my value for the where clause, so I'm selecting several tables and joining them through the Database Expert Links tab. All works fine, but after doing that and then parsing the parameter with the below formula in the Select Expert, I notice that there is no where clause in the SQL query, and although the report eventually displays the proper values, it runs through thousands of records first. Here is my Select Expert - Record formula:
StringVar array Parm1;
Parm1 := Split({?DATA_AREA}, "|");
{SO_ORDERS.CASE_ID} = Parm1[2]
If I change "Parm1[2]" on the last line to a valid Case ID, then there is a where clause in the SQL and the report generates immediately.
It seems like the record select formula is applied AFTER all of the records (without a where clause) are searched when I use the parsed parameter value, but when I hard code a valid value, it places that into the where clause BEFORE the sql is executed. Is there a way to get the parameter parsed first and then use that parsed value in the SQL where clause?
Thanks.
BillYes crystal will run the query first to get 100% data and then applies record selection condition. To increase the performance you need to pass the where condition at the command level instead of report level. So you need to create a report using add command like this
select * from tablename where field={?Parameter}
{?Parameter} is a command level parameter.
Now insert this report as a subreport in another report which has no connection but has a parameter
{?DATA_AREA} and create a formula like this in the main report
Split({?DATA_AREA}, "|")[2]
Now right click on the subreport and go to change subreport links and add this formula from main report and link this to sub report parameter {?Parameter} without linking any database field from the subreport.
Now your subreport runs with the where clause to get the data.
Regards,
Raghavendra -
How to pass the parameter in the where clause of the select statement
Hi All,
Iam getting one of the value from the Input otd and using this value i need to query one of the tables in oracle database and selected the table using the oracle eway otd like shown below .
otdRISKBLOCK_1.getRISKBLOCK().select() .
where clause in side the select takes a string parameter as Iam getting the string parameter from the input otd and passing this to where clause by creating a string literal after deployment it is giving an error saying "ORA-00920: invalid relational operator".
can any one throw some input on this .
Thanks in Advance
SrikanthYou will see this error if the search condition was entered with an invalid or missing relational operator.
You need to include a valid relational operator such as
=, !=, ^=, <>, >, <, >=, <=, ALL, ANY, [NOT] BETWEEN, EXISTS, [NOT] IN, IS [NOT] NULL, or [NOT] LIKE in the condition. in the sql statement.
Can you throw some more light on how are you designing your project? -
How do I modify the WHERE clause in my SQL query?
This seems like such a straight-forward part of the report design, but I'm fairly new to Crystal Reports and I only have experience with modifying reports someone else has already written. In this particular case, I just need to modify the WHERE clause of the SQL query. I can select Show SQL Query and see what statement is being used to select data, but I can't find where to modify it since it's grayed out. I see how to change the selection criteria, parameters, grouping, etc...just not the WHERE clause. The report is linked to a database used for reporting with a table created and populated by a stored procedure. I don't need to modify the stored procedure because the data I want to filter by is currently in the table--I just don't know how to filter by what I need. Here's part of the query:
SELECT "rpt_dist"."startdate", "rpt_dist"."transtype", "rpt_dist"."laborcode", "rpt_dist"."crewid", "rpt_dist"."regularhrs" FROM "Reporting"."dbo"."rpt_dist" "rpt_dist"
WHERE (rpt_dist."transtype" <> 'WORK' AND rpt_dist."transtype" <> 'WMATL') AND rpt_dist."laborcode" LIKE 'S%' AND (rpt_dist."crewid" = 'HOUS' OR rpt_dist."crewid" = 'HOUS2' ...
I would like to add another crewid to the WHERE clause. Thanks for any input.1.Open the report in the crystal designer
2.Go to the field explorer(if hidden go to view menu->field explorer)
3.Rt. click on the database fields->choose database expert
4.Now you will see 2 columns-Available DataSource and Selected Tables
5.Rt. click on the object(ex.command) available in the Selected Tables column->Choose Edit command
6.A new Modify Command window will appear,here you can edit your SQL Query
I get to step 4 and I see the two columns including my database and the report table, but there is no command object available. If I right-click on my table, I can just view the Properties. ??
As for the other tip to modify the record selection: I don't see anywhere the other crewid values are set and if I add the one I'm missing, it doesn't modify the existing SQL Query and when I preview the report it throws off the results so that no data displays??
I'm using Crystal Reports 11.5 if that makes a difference. Thanks again. -
Using if logic in the where clause of a select statement
I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
Basically I am looking for a case statement like this
case
when all_off_trt = 'Y' and mail_para.code = 'Y' then false
else true
end
Message was edited by:
Tugnutt7Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
This is currently what I have, tested and working 100%.
cursor email_cur is
select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
from participant p, trialcom t, ethics s
where p.status='A'
and p.surname=t.surname
and p.initials=t.initials
and s.trial_cd = t.tricom
and s.centre = t.centre
and p.email is not null
and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable. -
Re: [iPlanet-JATO] How to make an OR in the WHERE clause of a SELECT
Harry,
If you get a reference to your model, you can set the
whereClauseOverride with exactly the string you want to use. Keep in
mind that you are dealing with a the raw SQL where clause, therefore,
you must use the actual table column names and not the model's logical
field names as they could be different.
QueryModelBase queryModel = (QueryModelBase)getModel(PersonModel.class);
// you must add the "WHERE" as well
String whereClause = "WHERE firstName LIKE '%max' OR lastName LIKE '%max%'";
queryModel.setWhereClauseOverride(whereClause);
Keep in mind that this will override all where criteria: static and
dynamic where criteria. Static criteria can be declared in your model
class: setStaticWhereCriteriaString(STATIC_WHERE_CRITERIA).
You could optionally get the entire SQL statement and replace the
__WHERE__ token yourself with a string replace technique. In fact, if
you want to add an ORDER BY, you will need to get the SQL and append to
the end.
queryModel.getSelectSQL();
Hope this helps. Let me know if you have any questions
craig
hlamer wrote:
Hi,
if I add criterias to my model
with "SelectQueryModel.addUserWhereCriterion()" they will be concated
with AND.
How can I add a criteria with OR?
I want something like:
SELECT personId, firstName, lastName
FROM Person
WHERE firstName LIKE "%max"
OR lastName LIKE "%max%"
Thanks.
Harry
For more information about JATO, including download information, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jspRewritten your query wuth tags as well
{code}select "P_CIRCUITS_FIBER"."PORTS_1",
"P_CIRCUITS_FIBER"."PORTS_2",
CASE WHEN CPORT.ID = (select REGEXP_SUBSTR(ports_1,'[^,]+',1,1) from p_circuits_fiber)
THEN "CPORT"."PORT_NO" END PORT_NO_1,
CASE WHEN CPORT.ID = (select REGEXP_SUBSTR(ports_2,'[^,]+',1,1) from p_circuits_fiber)
THEN "CPORT"."PORT_NO" END PORT_NO_2
from "CPORT",
"P_CIRCUITS_FIBER"
where p_circuits_fiber.fiber_id = :P4000_CIRCUIT_NO
and (select REGEXP_SUBSTR(ports_1,'[^,]+',1,1) from p_circuits_fiber) = "CPORT"."PORT_NO" "PORT_NO_1"
and (select REGEXP_SUBSTR(ports_2,'[^,]+',1,1) from p_circuits_fiber) = "CPORT"."PORT_NO" "PORT_NO_2"{code}
Now we can see two columns references which should not be there.
I even not sure to understand why those two conditions are in the WHERE clause. But for sure, CPORT.ID cannot be equal to two values unless they are same.
Is there only one row in p_circuits_fiber ?
Nicolas. -
JSP, Data Web Bean, BC4J: Setting the where clause of a View Object at run time
Hi,
I am trying to develop a data web bean in which the where clause of a View Object will be set at run time and the results of the query then displayed.
My BC4J components are located in one project while the coding for the data web bean is in another project. I used the following code bu t it does not work. Could you please let me know what I am doing wrong?
public void populateOSTable(int P_EmpId)
String m_whereString = "EmpView.EMP_ID = " + P_EmpId;
String m_OrderBy = "EmpView.EMP_NAME";
oracle.jbo.ApplicationModule appModule = null;
ViewObject vo = appModule.findApplicationModule("EMPBC.EMPAppModule").findViewObject("EMPBC.EMPView");
vo.setWhereClause(m_whereString);
vo.setOrderByClause(m_OrderBy);
vo.executeQuery();
vo.next();
String empName numAttrs = vo.getAttribute(EmpName);
System.out.println(empName);
Thanks.<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by JDev Team (Laura):
Here is how I have usually done mine:
1. In the JSP, use a RowsetNavigator bean to set the where clause and execute the query.
2. Use a custom web bean to process the results of the query (print to HTML).
for example:
<jsp:useBean class="oracle.jbo.html.databeans.RowsetNavigator" id="rsn" scope="request" >
<%
// get the parameter from the find form
String p = request.getParameter("p");
String s = request.getParameter("s");
// store the information for reference later
session.putValue("p", p);
session.putValue("s", s);
// initialize the app module and view object
rsn.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
// set the where clause string
String theclause = "presname = '" + p + "' AND slideno=" + s;
// set the where clause for the VO
rsn.getRowSet().getViewObject().setWhereClause(theclause);
rsn.getRowSet().getViewObject().executeQuery();
rsn.getRowSet().first();
%>
</jsp:useBean>
<jsp:useBean class="wt_bc.walkthruBean" id="wtb" scope="request" >
<%
// initialize the app module and VO
wtb.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
wtb.render();
%>
In this case, the render method of my custom web bean mostly gets some session variables, and prints various content depending on the session variable values.
Hope this helps.
</jsp:useBean><HR></BLOCKQUOTE>
Laura can you give the code of your walkthru bean? i wna't to initialize a viewobject, set the where clause and give that viewobject back to initialize my navigatorbar.
Nathalie
null -
How to retrieve the 'Where Clause' text?
Hello all,
I have created a package to retrieve all the DML's executed against the database for the day, for a particular user. DBMS_LOGMNR package was used to retrieve DMLs. But the DMLs retrieved have their 'WHERE' clause text converted to ROWID's. I need to find out the 'WHERE' clause with the parameters.
I tried retrieving values from the v$sql views, but that information is cryptic and very volatile.
Is there a way to retrieve the 'Where' clause? If not, is there a way to retrieve the 'WHERE' clause information using a trigger against the corresponding table.
I am desparately lookin'for a solution. Hope someone out there can help me out.
Regards,
Prabu Raghav.Hi Andrew,
Thanks for the suggestion.
I am using Oracle 8i not 9i.FGA using DBMS_RLS let's me add policies and retrieve all other information about a user except the SQL statement that's executed by the user.
I want to retrieve the Current sql statement executed against the table by a particular user and record it.
Any suggestions?
Regards,
Prabu Raghav. -
To_Date function in the Where Clause
Hello All,
I'm having an issue using the to_date function that has me quite perplexed.
I have two varchar2 fields, one with a date value in the format Mon, DD YYYY, the other has a time value in the format HH:MI PM.
When I run my query one of the columns I retrieve looks like this TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM'). The two fields are concatenated together and converted to a date. This works fine.
My problem occurs when I attempt to apply the same logic to the where clause of the aforementioned query. e.g. when I add the following criteria to my query and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate I get an ORA-01843: not a valid month error.
To further illustrate my problem here are the two queries:
Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
from ....
where ....
The above query works.
Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
from ....
where ....
and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate
The second query does not work.
The tables used and the limiting criteria are identical, except for the last one.
Does anyone have any ideas why this could be happening.
erHello,
Check this out. It does work. Do cut n paste sample
data from your tables.
SQL> desc test
Name Null? Type
ID NUMBER
DDATE VARCHAR2(20)
DTIME VARCHAR2(20)
SQL> select * from test;
ID DDATE DTIME
1 Jan, 10 2006 12:32 PM
2 Mar, 11 2005 07:10 AM
3 Apr, 13 2006 03:12 AM
4 Nov, 15 2003 11:22 PM
5 Dec, 20 2005 09:12 AM
6 Oct, 30 2006 10:00 AM
7 Jan, 10 2006 12:32 PM
8 Apr, 11 2005 07:10 AM
9 May, 13 2006 03:12 AM
10 Sep, 15 2003 11:22 PM
11 Oct, 20 2005 09:12 AM
12 Dec, 30 2006 10:00 AM
12 rows selected.
SQL> select id, ddate, dtime,
2 to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM') AA,
A,
3 to_char(to_date(ddate||dtime,'Mon, DD YYYYHH:MI
MI PM'),'Mon, DD YYYYHH:MI PM') BB
4 from test;
ID DDATE DTIME
DTIME AA BB
1 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
2 Mar, 11 2005 07:10 AM
07:10 AM 11-MAR-05 Mar, 11 200507:10 AM
3 Apr, 13 2006 03:12 AM
03:12 AM 13-APR-06 Apr, 13 200603:12 AM
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03 Nov, 15 200311:22 PM
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05 Dec, 20 200509:12 AM
6 Oct, 30 2006 10:00 AM
10:00 AM 30-OCT-06 Oct, 30 200610:00 AM
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05 Apr, 11 200507:10 AM
9 May, 13 2006 03:12 AM
03:12 AM 13-MAY-06 May, 13 200603:12 AM
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03 Sep, 15 200311:22 PM
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05 Oct, 20 200509:12 AM
12 Dec, 30 2006 10:00 AM
10:00 AM 30-DEC-06 Dec, 30 200610:00 AM
12 rows selected.
SQL> select id, ddate, dtime,
to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
2 from test
3 where id > 3
4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
') <= trunc(sysdate);
ID DDATE DTIME
DTIME TO_DATE(D
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05
6 rows selected.
SQL> select id, ddate, dtime,
to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
2 from test
3 where id > 3
4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
') <= sysdate;
ID DDATE DTIME
DTIME TO_DATE(D
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05
6 rows selected.
-SriSorry Sri, but I fail to see what you mean. How is what you're doing any different than what I'm doing? -
Query Tuning - using CASE statement in the WHERE clause
Hi All,
My query has been modified to use a CASE statement in the WHERE clause to consider data from certain columns based on a parameter value. This modified query is doing a full table scan and running endlessly. Please suggest what may be done to improve its performance:
Query:
SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
os.acctnum,
os.avieworigin_refid,
COUNT(1) cnt_articleview,
SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
FROM TABLE1 os
WHERE os.acctnum IS NOT NULL
AND os.avieworigin_refid IS NOT NULL
AND os.requestdatetime IS NOT NULL
AND UPPER(os.success_ind) = 'S'
AND CASE WHEN
Param_ValueToCheck = 'FULL' AND get_date_timestamp(os.requestdatetime) BETWEEN
TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
WHEN
Param_ValueToCheck = 'INCR' AND os.entry_createddate BETWEEN
TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
END = 1
AND CASE WHEN
Param_ValueToCheck = 'FULL' AND os.entry_CreatedDate BETWEEN
TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
WHEN
Param_ValueToCheck = 'INCR' THEN 1
END = 1
GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Table Description:
(Number of rows : approx > 600,000,000)
Name Null Type
ARTICLEID NOT NULL NUMBER(20)
USERKEY NUMBER(10)
AVIEWORIGIN_REFID VARCHAR2(10)
SUCCESS_IND VARCHAR2(2)
ENTRY_CREATEDDATE DATE
CREATED_BY VARCHAR2(10)
FILENUMBER NUMBER(10)
LINENUMBER NUMBER(10)
ACCTNUM VARCHAR2(10)
AUTOCOMPLETEDTERM NUMBER(2)
REQUESTDATETIME VARCHAR2(19)Explain Plan
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 2224314832
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 590 | 33040 | 2501K (1)| 08:20:15 | | |
| 1 | HASH GROUP BY | | 590 | 33040 | 2501K (1)| 08:20:15 | | |
| 2 | PARTITION RANGE ALL| | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575|
|* 3 | TABLE ACCESS FULL | TABLE1 | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575|
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE WHEN ('FULL'='FULL' AND
"OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE WHEN ('FULL'='FULL'
AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
PLAN_TABLE_OUTPUT
2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
"OS"."AVIEWORIGIN_REFID" IS NOT NULL)Edited by: Chaitanya on Jun 9, 2011 2:44 AM
Edited by: Chaitanya on Jun 9, 2011 2:47 AMHi Dom,
Modified Query:
SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
os.acctnum,
os.avieworigin_refid,
COUNT(1) cnt_articleview,
SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
FROM TABLE1 os
WHERE os.acctnum IS NOT NULL
AND os.avieworigin_refid IS NOT NULL
AND os.requestdatetime IS NOT NULL
AND UPPER(os.success_ind) = 'S'
AND (('FULL' = 'FULL'
AND (get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
OR ('FULL' = 'INCR'
AND os.entry_createddate BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') ))
GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Execute Plan:
PLAN_TABLE_OUTPUT
Plan hash value: 3615447714
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 25125 | 1374K| | 407K (1)| 01:21:36 | | |
| 1 | HASH GROUP BY | | 25125 | 1374K| 3768K| 407K (1)| 01:21:36 | | |
| 2 | PARTITION RANGE ITERATOR| | 25125 | 1374K| | 407K (1)| 01:21:32 | 29 | 31 |
|* 3 | TABLE ACCESS FULL | TABLE1 | 25125 | 1374K| | 407K (1)| 01:21:32 | 29 | 31 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
3 - filter("OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
UPPER("OS"."SUCCESS_IND")='S' AND "OS"."REQUESTDATETIME" IS NOT NULL AND
"ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))Edited by: Chaitanya on Jun 9, 2011 4:51 AM -
Function-based Index and an OR-condition in the WHERE-clause
We have some problems with functin-based indexes and
the or-condition in a where-clause.
(We use oracle 8i (8.1.7))
create table TPERSON(ID number(10),NAME varchar2(20),...);
create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
The following two statements run very fast on a large table
and the execution-plan asure the usage of the indexes
(-while the session is appropriate configured and the table is analyzed):
1) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
2) select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
In particular we see that a normal index is used while the where-clause contains
an OR-CONDITION.
But if we try the similarly select-statement
3) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
the CBO will not use the function-index.
(This behavior we only expect with views but not with indexes.)
We ask for an advice like an hint, which enable the CBO-usage
of function-based indexes in connection with OR.
This problem seems to be artificial because it contains this dummy logic:
or (3=5).
This steams from an prepared statement, where this kind of boolean
flag reduce the amount of different select-statements needed for
covering the hole business-logic, while using bind-variables for the
concrete query-parameters.
A more realistic (still boild down) version of our prepared select-statement run in
SQL Plus:
define x_name = 'MIL%';
define x_firstname = '';
select * FROM TPERSON
where (upper(NAME) like '&x_name' or ( '&x_name' = ''))
and (upper(FIRSTNAME) like '&x_firstname' or ('&x_firstname' = ''))
and ...;
In particular we dont refernce the tablecolumn , but the QUERY-Parameter
yield the second boolean value in the or-condition.
The problem is that this condition ('&x_name' = '') dont use any index.
thanks a lot for spending your time with this problemTry
SELECT /*+ RULE */
as your hint. I don't have the book with me, but this last weekend I read a section about your very problem. The book was a Oracle Press gold cover about Oracle 8i Performance tuning. If you e-mail me I can quote you the chapter when I get home Friday. -
How to use multiple search conditions in the where clause
Hi,
Below is my query
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctacct,sum(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
This one gives me the exact result i want, now if i add one more to my where clause like this
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctacct,sum(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTACCT like'[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%' or
CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
This query doesnt give me the exact values instead it gives me all the weird values.Can someone please help me with how to work on this where clause?
ThanksHi Patrick,
This is what i ve tried earlier and it isnt working .If i use the first query
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctdesc,SUM(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
--OR
--CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
and GLYEAR = 2014
and CTDESC = 'Sales'
group by ctdesc
The result set is
Sales
-182273.96
And if i use the second query
SELECT distinct
ctdesc,SUM(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
OR
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
and GLYEAR = 2014
and CTDESC = 'Sales'
group by ctdesc
The result set i get is
Sales
-1455441.08
And i verified that CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
this second line of where clause has not desc as Sales.
I am not sure whats causing the difference in the values.
Can you please help me with this?
Thanks -
Error witth a parameter in a WHERE clause
Hi experts I have the following code from an abap programa
I have done a conection with Sql
And I want to do a SELECT.. WHERE one value from a column in the table is the same that the ones I write like an input parameter... but when is done the comparation
appears the 207 error from Sql I don't know how to fix it
Please help me ¡¡
REPORT Z_CONEXBD_ARACELI2.
DATA: c_copi TYPE FLIGHTS-COPILOT.
DATA: c_pilot TYPE FLIGHTS-PILOT.
DATA: c_id TYPE FLIGHTS-ID.
DATA: con_name LIKE dbcon-con_name VALUE 'CON'.
*Here is the declaration of the parameter
PARAMETERS: P_PILOT LIKE FLIGHTS-PILOT.
EXEC SQL.
SET CONNECTION :con_name
ENDEXEC.
IF sy-subrc <> 0.
Connection not yet opened.
EXEC SQL.
CONNECT TO :con_name
ENDEXEC.
endif.
Do something on connection 'con_name'
EXEC SQL.
select PILOT, COPILOT, ID
into :c_pilot, :c_copi, :c_id
from FLIGHTS
*Here is the where clause comparing with the parameter P_PILOT
Where PILOT = P_PILOT
ENDEXEC.
*Commit the changes on 'con_name'
EXEC SQL.
COMMIT
ENDEXEC.
EXEC SQL.
SET CONNECTION :con_name
ENDEXEC.
EXEC SQL.
DISCONNECT :con_name
ENDEXEC.
WRITE: /5 'CATALOGO DE VUELOS'.
WRITE: /5 :c_copi, :c_pilot, :c_id.
Thank you very much
Edited by: ARACELI GONZALEZ on Jun 9, 2008 3:51 AMHi , I think this is a post for abap programmers.
Antonio. -
Query Builder won't apply chosen date to the where clause
Does anybody know why when I chose a date field, in the where clause, when using Query Builder, it won't actually write the chosen date to the actual query?
If I select the "View Query" tab, no date shows up. Also if I press the "Run Report" button in the "View Result" tab, I get this error:
"An error was encountered performing requested operation: ORA-00936: missing expression"
This is because actual date data is missing.
After I hit the "Apply" button, I have to manually type the date data.
I thought this was a bug of the previous version, but I just installed version 1.5.4 and I have no different result.
Thanks.I just wanted to add my name to the list of people having this issue.
Oracle Techies, please help. -
Hi all,
Can anyone suggest an appropriate answer for this
I want to change the where condition in Reports (Developer 2000) dynamically (in runtime)
Thank youHi,
Try this in you pre-query trigger.
-- if you want to add to the where clause do this
-- first store the current where clause
C_WHERE := get_block_property('your_block', default_where);
IF <condition> THEN
c_where := 'desired_condition'||' AND '||C_where;
-- append your condition to the existing one.
END IF;
set_block_property('your_block', default_where,c_where);
or if you want to totally replace it just use the set_block_property in the trigger.
Hope this helps.
Bob
Maybe you are looking for
-
Understanding open syscall on FIFO with dtrace
Hi all, I'm trying to understand open syscall behaviour with respect to FIFOs using dtrace. We have a very intermittent failure with FIFOs, when writer process fails in opening pipe, but reader succeeds. I tried debugging with dtrace and found some w
-
Hi, I want to develop a task (webdynpro) with a simple button to close the task (not to complete the task). How can I do it?
-
MF50 : Planning table and planning time fence
HI, I use the transaction MF50 as planning table ( in order to do my MPS planning), I use "set firming date" to fix a firming date. Now, I want o know if it should possible to reveal a message when we create a planned order within the firming date??
-
Hi, this is the first time i use different ip on both rac nodes. Will this post a problem? for example public ip: node 1 192.168.0.100 node 2 192.168.0.101 I am not sure the following errors related to the public IPs above, but I am seeing. css.log 2
-
Help with printer and displays c?alibration
Good afternoon I need help processing and printing photos. My hardware is: • Macbook Pro 13 "Intel Core 2 Duo with 4GB Ram 2:53 and running MacOSX 10.6.6 • Wacom Cintiq 21UX • Canon Pixma iP4850. I treatment of images in Adobe Lightroom 3; CINTIQ my