Range query and case
I am testing on Oracle 10g R2, trying to work on a range query.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/sql_1016.htm#i28528
I have used CASE as follows;
test@>explain plan for
2 select count(*) from rm_supplies
3 where item_no < 40000;
Explained.
test@>SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());
PLAN_TABLE_OUTPUT
Plan hash value: 1332725657
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 5 | 8748 (7)| 00:01:45 | | |
| 1 | SORT AGGREGATE | | 1 | 5 | | | | |
| 2 | PARTITION RANGE ITERATOR| | 5542K| 26M| 8748 (7)| 00:01:45 | 1 | 2 |
| 3 | INDEX FAST FULL SCAN | RM_SUPPLIES_IDX1 | 5542K| 26M| 8748 (7)| 00:01:45 | 1 | 2 |
10 rows selected.
test@>explain plan for
2 select count(*) from rm_supplies
3 where item_no between 40000 and 60000;
Explained.
test@>SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());
PLAN_TABLE_OUTPUT
Plan hash value: 1332725657
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 5 | 8818 (8)| 00:01:46 | | |
| 1 | SORT AGGREGATE | | 1 | 5 | | | | |
| 2 | PARTITION RANGE ITERATOR| | 4028K| 19M| 8818 (8)| 00:01:46 | 3 | 5 |
|* 3 | INDEX FAST FULL SCAN | RM_SUPPLIES_IDX1 | 4028K| 19M| 8818 (8)| 00:01:46 | 3 | 5 |
Predicate Information (identified by operation id):
3 - filter("ITEM_NO"<=60000)
15 rows selected.
test@>explain plan for
2 select count(*) from rm_supplies
3 where item_no > 60000;
Explained.
test@>SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());
PLAN_TABLE_OUTPUT
Plan hash value: 2956645916
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 5 | 2037 (3)| 00:00:25 | | |
| 1 | SORT AGGREGATE | | 1 | 5 | | | | |
| 2 | PARTITION RANGE ITERATOR| | 845K| 4126K| 2037 (3)| 00:00:25 | 5 | 7 |
|* 3 | TABLE ACCESS FULL | RM_SUPPLIES | 845K| 4126K| 2037 (3)| 00:00:25 | 5 | 7 |
Predicate Information (identified by operation id):
3 - filter("ITEM_NO">60000)
15 rows selected.
test@>ed
Wrote file afiedt.buf
1 explain plan
2 for
3 select count(case when item_no < 40000
4 then 1 ELSE null END) count1,
5 COUNT (CASE WHEN item_no BETWEEN 40000 and 60000
6 then 1 ELSE null END) count2,
7 COUNT (CASE WHEN item_no > 60000
8 THEN 1 ELSE null END) count3
9* from rm_supplies
10 /
Explained.
test@>SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());
PLAN_TABLE_OUTPUT
Plan hash value: 3589921989
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 5 | 8597 (5)| 00:01:44 | | |
| 1 | SORT AGGREGATE | | 1 | 5 | | | | |
| 2 | PARTITION RANGE ALL | | 10M| 49M| 8597 (5)| 00:01:44 | 1 | 7 |
| 3 | INDEX FAST FULL SCAN| RM_SUPPLIES_IDX1 | 10M| 49M| 8597 (5)| 00:01:44 | 1 | 7 |
10 rows selected.Can there be any other way that I could recreate the range query?
Thank you,
Adith
Thank you for the reply. I was hoping for a similar answer as you have stated;
index fast full scan could be the best way to get the needed information. So then there is no need to recreate or change the query.
Thank you once again.
Adith
Similar Messages
-
Concatenate results SQL query and CASE use Report Builder Reporting Services
I need to concatenate the results from a SQL query that is using CASE. The query is listed below. I do not need permitsubtype but I need to concatenate the results from the permittype.
I tried deleting the permitsubtype query and it would not run correctly. Please see the query and diagram below. Any help is appreciated.
select PERMIT_NO
,(case when
ISNULL(PERMITTYPE,'') = ''
then 'Unassigned'
else (select LTRIM(RTRIM(PERMITTYPE)))
END) AS PERMITTYPE
,(case when
ISNULL(PERMITSUBTYPE,'') = ''
then 'Unassigned'
else (select LTRIM(RTRIM(PERMITSUBTYPE)))
END) AS PERMITSUBTYPE
,ISSUED
,APPLIED
,STATUS
,SITE_ADDR
,SITE_APN
,SITE_SUBDIVISION
,OWNER_NAME
,CONTRACTOR_NAME
,ISNULL(JOBVALUE,0) AS JOBVALUE
,FEES_CHARGED
,FEES_PAID
,BLDG_SF
from Permit_Main
where ISSUED between @FromDate and @ToDateHi KittyCat101,
As per my understanding, you used case when statement in the query, you do not need to display permitsubtype in the report, but when you tried to delete permitsubtype from the query, it could not run correctly. In order to improve the efficiency of troubleshooting,
I need to ask several questions:
“I tried deleting the permitsubtype query and it would not run correctly.” As we can see, it has no effect to delete permitsubtype from the query you provided, could you please provide complete sql query for the report?
Could you please provide detailed information about the report? I would be appreciated it if you could provide sample data and screenshot of the report.
Please provide some more detailed information of your requirements.
This may be a lot of information to ask for at one time. However, by collecting this information now, it will help us move more quickly toward a solution.
Thanks,
Wendy Fu -
Query that treats "accents insensitive" and "case insensitive"
I need to do one query that treats "accents insensitive" and "case insensitive" if possible too.
I need to have the query below ajusted to return both accent or not accent words:
with t as
( select 'xxxELEIÇÕESyyy' text from dual union all
select 'xxxELEIÇOESyyy' text from dual union all
select 'xxxELEICÕESyyy' text from dual)
select text from t
where text like '%eleicoes%'; --> i need some filter that result true for both 3 linesSQL> with t as
2 ( select 'xxxELEIÇÕESyyy' text from dual union all
3 select 'xxxELEIÇOESyyy' text from dual union all
4 select 'xxxeleiÇOESyyy' text from dual union all
5 select 'xxxELEICÕESyyy' text from dual)
6 select text from t
7 where regexp_like(t.text, '(x|X){3}(ELEI|elei){1}([CcÇç]{1})([ÕOõo]{1})(ES|es){1}(y|Y){3}')
8
SQL> /
TEXT
xxxELEIÇÕESyyy
xxxELEIÇOESyyy
xxxeleiÇOESyyy
xxxELEICÕESyyy -
How to query using 3 optional inputs and case insensitive using SQL?
Hi Folks,
I am having trouble with the following query:
select *
from t1
where (1=1)
and lower(fname) like lower ('%mary%')
and lower(lname) like lower ('%smith%')
and lower(status) like lower ('%%')
I need all three statements in the where clause to be completely optional and case insensitve.
if I just write the following:
(1=1)
and lower(fname) like lower ('%mary%')
and lower(lname) like lower ('%%') <-- Need to ignore this line
and lower(status) like lower ('%%') <-- need to ignore this line
nothing is returned. How do I ignore the 2nd and third lines using SQL only. I know about the ask TOM Article using procedures, but I need to do this using SQL only
thanks in advance
Edited by: user2184537 on Oct 16, 2009 9:40 AM
Edited by: user2184537 on Oct 16, 2009 10:10 AMHi,
Is this query generated dynamically? (That's the only reason I can see for saying "WHERE 1 = 1".)
If so, test the parameters for NULL, and only add them if a value was given.
Failing that, you can explicitly test for NULL parameters
where ( lower(fname) = '%' || lower (:p_fname) || '%'
OR :p_fname IS NULL
and ( lower(lname) = '%' || lower (:p_lname) || '%'
OR :p_lname IS NULL
and ( lower(status) = '%' || lower (:p_status) || '%'
OR :p_status IS NULL
)Did you really mean to have all those '%''s? '%' is a wildcard in LIKE operations, but not when using =.
Perhaps you should be saying:
where ( lower(fname) = lower (:p_fname)
OR :p_fname IS NULL
and ( lower(lname) = lower (:p_lname)
OR :p_lname IS NULL
and ( lower(status) = lower (:p_status)
OR :p_status IS NULL
)You're already handling case-sensitivity, by using LOWER in all the comparisons.
Unfortunately, you can't just say something like:
WHERE LOWER (fname) = LOWER (NVL (:p_fname, fname))because that would discartd rows where fname IS NULL when :p_name is also NULL.
Edited by: Frank Kulash on Oct 16, 2009 12:54 PM -
Hi,
i have created a query on YTD sales query and comparison with the previous year. i have created a structure using 0calmonth2 info object and restricted it for each month starting from July to June. In the key figures i have used sales values key figure and restricted one with variable 0I_PRFYE for all fiscal year periods of previous year and for the current year i used a value range from 001.YYYY to the current fiscal year period. where YYYY is the same fiscal year as in current fiscal year period.
After executing the query for sales values in previous year i have a value against every fiscal year period in the previous year. For the current year i have the value only for the first month as we are in the first month.
example:
jul aug sep oct nov dec jan feb mar apr may jun
Current year 17 0 0 0 0 0 0 0 0 0 0 0
Previous Year12 13 18 34 23 67 20 10 83 34 25 27
When i creating a line chart based on this data, for the current year the line drops from jul to aug and continues to be zero through out the year. what i am expecting is it should not drop to zero as we have not yet come to aug in the current year. What i am expecting is that the line should be showing as a dot in the current month jun, when the current fiscal year period is aug i will have some value in the aug so the chart should show a line from jul to aug.
I tried to change the display of zero's as blank & even tried replacing zeros with some characters but could not achieve the desired result.
can some body help me achieve this. Correct responses will be awarded appropriately.
Regards,
Ravi.Hi,
The line chart shows the two series one for previous year and one for current year.
the issue is with current year. as the value for aug is blank the line chart drops to zero on the y axis. What i want to achieve is that as i am not yet in aug and my current fiscal yera period is jul i dont want the line to drop to zero. in this case i want it to be just a dot on y axis depending on the value. Once my current fiscal year period is aug i want a line from jul to aug only. In the current senario if my current fiscal year period is aug i will have the line from jul to aug but then drops to zero on y axis for sep. I dont want that to happen.
Hope iyou understand what i am trying to explain.
Thanks for your reply.
Ravi. -
Is this possible? range query
I have a db with keys/data as the following
Key data
AA data1
AB data2
AA data3
AB data4
AA data5
AB data6
what I expect is
if search by key =AA return data1,3,5,
if searcy by key = A, return all records
when I query using DB_SET_RANGE
query A, only get all records with key ==AA
seems this is correct output based on the API description, while this is not so-called range query.
is it possible to get what I expect above? use a new BTree comparsion function? if so, AA and AB is treated as the same key, and will not be able to differentiate AA and AB.
right?
there are several threads on this, did not the answer. thanks
The DB_SET_RANGE flag is identical to the DB_SET flag, except that in the case of the Btree access method, the key is returned as well as the data item and the returned key/data pair is the smallest key greater than or equal to the specified key (as determined by the Btree comparison function), permitting partial key matches and range searchesHi,
Let's consider your database:
key data
AA data1
data3
data5
AB data2
data4
data6
If you do a DBC->c_get() with DB_SET_RANGE and as search key "A" than the cursor will be positioned on the first key/data pair AA - data1. This is correct and complies with the documentation. If you than iterate with DB_NEXT on the DBC->c_get() call (as presented in the previous range_query function) you will sequentially retrieve each record within the database (the records are sorted lexically by key, and duplicates are sorted lexically on the data portion - by default). When you iterate with DB_NEXT_DUP on the DBC->c_get() call you will retrieve the records with the "AA" key.
If you do the DBC->c_get() with DB_SET_RANGE and a search key "AA" than the cursor will be positioned, as in the previous case, on the first key/data pair AA - data1. The same applies when iterating with DB_NEXT or DB_NEXT_DUP.
When you do a range search on "AA" and iterate with DB_NEXT you will get all the records because all the records have the key equal or greater (lexically) than "AA".
The same goes for a range search on "A" and iterating with DB_NEXT.
If you expect to get data1, data 2, data3 when searching on "AA" than this is not a range search, it is a simple query (done with DB_SET initially and than iterate with DB_NEXT_DUP).
If you use the function that I posted previously (exactly as it is) and you pass it "A" as searchKey then you will retrieve all the records, just as you expected.
Here is an excerpt from the documentation:
DB_SET
Move the cursor to the specified key/data pair of the database, and return the datum associated with the given key.
The DBcursor->c_get method will return DB_NOTFOUND if DB_SET is set and no matching keys are found. The DBcursor->c_get method will return DB_KEYEMPTY if DB_SET is set and the database is a Queue or Recno database, and the specified key exists, but was never explicitly created by the application or was later deleted. In the presence of duplicate key values, DBcursor->c_get will return the first data item for the given key.
DB_SET_RANGE
The DB_SET_RANGE flag is identical to the DB_SET flag, except that in the case of the Btree access method, the key is returned as well as the data item and the returned key/data pair is the smallest key greater than or equal to the specified key (as determined by the Btree comparison function), permitting partial key matches and range searches.I hope this clarifies the way to deal with a range query, if not then let me know and I will present a program that demystifies this.
Best regards,
Andrei -
Date range query problem in report
Hi all,
I have created a report based on query and i want to put date range selection but query giving problem.
If i am creating select list selection then it is working fine means it will display all records on the particular date.
But what i need is that user will enter date range as creation_date1,creation_date2 and query should return all the records between these date range. i want to pass it by creating items, i created two items and passing creation_date range to display all records but not displaying and if not passing date then should take null as default and display all records
Here is the query:
/* Formatted on 2006/12/10 20:01 (Formatter Plus v4.8.0) */
SELECT tsh."SR_HEADER_ID", tsh."SALES_DEPT_NUMBER", tsh."COUNTRY",
tsh."LOCAL_REPORT_NUMBER", tsh."ISSUE_DATE", tsh."SUBJECT",
tsh."MACHINE_SERIAL_NUMBER", tsh."MACHINE_TYPE", tsh."MACHINE_HOURS",
tsh."STATUS"
FROM "TRX_SR_HEADERS" tsh, "TRX_SR_PARTS" tsp
WHERE (tsh.status LIKE :p23_status_sp OR tsh.status IS NULL)
AND (tsh.machine_type LIKE :p23_machine_type_sp)
AND ( tsh.machine_serial_number LIKE
TO_CHAR (:p23_machine_serial_number_sp)
OR tsh.machine_serial_number IS NULL
AND ( TO_CHAR (tsh.failure_date, 'DD-MON-YY') LIKE
TO_CHAR (:p23_failure_date_sp)
OR TO_CHAR (tsh.failure_date, 'DD-MON-YY') IS NULL
AND ( TO_CHAR (tsh.creation_date, 'DD-MON-YY')
BETWEEN TO_CHAR (:p23_creation_date_sp)
AND TO_CHAR (:p23_creation_date_sp1)
OR TO_CHAR (tsh.creation_date, 'DD-MON-YY') IS NULL
AND (tsh.issue_date LIKE :p23_date_of_issue_sp OR tsh.issue_date IS NULL)
AND (tsh.country LIKE :p23_country_sp OR tsh.country IS NULL)
AND ( tsh.local_report_number LIKE TO_CHAR (:p23_local_rep_num_sp)
OR tsh.local_report_number IS NULL
AND ( tsp.part_number LIKE TO_CHAR (:p23_part_number_sp)
OR tsp.part_number IS NULL
AND tsh.machine_type IN (
SELECT DISTINCT machine_type
FROM trx_sales_dept_machine_list
WHERE sales_department_id IN (
SELECT DISTINCT sales_department_id
FROM trx_user_sales_department
WHERE UPPER (user_name) =
UPPER ('&APP_USER.'))
AND SYSDATE >= valid_from)
AND tsh.sr_header_id = tsp.sr_header_id
can any one tell me wat is wroung in this query.
Any other way to write this?
Thank You,
AmitHi User....
Here is some date range SQL that my teams uses with some success:
For date columns that do not contain NULL values, try this (note the TRUNC, it might help with your "today" problem).
The hard coded dates allow users to leave the FROM and TO dates blank and still get sensible results (ie a blank TO date field asks for all dates in the future.
AND TRUNC(DATE_IN_DATABASE)
BETWEEN
decode( :P1_DATE_FROM,
TO_DATE('01-JAN-1900'),
:P1_DATE_FROM)
AND
decode( :P1_DATE_TO,
TO_DATE('31-DEC-3000'),:
:P1_DATE_TO)
For date columns that contain NULL values, try this (a little bit trickier):
AND nvl(TRUNC(DATE_IN_DATABASE),
decode( :P1_DATE_FROM,
decode( :P1_DATE_TO,
TO_DATE('30-DEC-3000'),
NULL),
NULL)
BETWEEN
decode( :P1_DATE_FROM,
TO_DATE('01-JAN-1900'),
:P1_DATE_FROM)
AND
decode( :P1_DATE_TO,
TO_DATE('31-DEC-3000'),
:P1_DATE_TO)
Note the 30-DEC-3000 versus 31-DEC-3000. This trick returns the NULL dates when the FROM and TO date range items are both blank.
I hope this helps.
By the way, does anyone have a better way of doing this? The requirement is given a date column in a database and a FROM and a TO date item on a page,
find all of the dates in the database between the FROM and TO dates. If the FROM date is blank, assume the user want all dates in the past (excluding NULL dates). If the TO date is blank, assume that the user wants all of the dates in the future (excluding NULL dates). If both FROM and TO dates are blank, return all of the dates in the databse (including NULL dates).
Cheers,
Patrick -
Need help in this query using Case Statement
I have the following query which is currently existing and I am adding few more conditions based on the new requirements which is based on a particular flag set as 1 or 0.
If it is set to 1 then I should use the old query as it is and if it is set to 0 then I should add the new conditions.
Basically when the flag is set to 0, I shouldnt be including some of the records that already exists and should include only new records. This is based on the plan_type_ids in (1,2,3,4).
Hence I am using the Case statement to check if the plan_type_id is in (1,2) then do a set of not exists and if the plan_type_id in (3,4) then do set of not exists.
But when I run this query it is giving me error. What am I doing wrong?
Is there any other simple way to combine all the not exists for all of those select statements as given after the line ------------------------- into a single one?
What am I doing wrong?
I tried putting the NOT EXists before the case too but that too didnt work.
Please help. Appreciate it.
Thank you in advance.
SELECT
ee.employee_id
,'WELCOMEMSG'
,DECODE( me.member_enrollment_id
,first_enr.enrollment_id
,20
,23
) status_id
,me.member_enrollment_id
,wk.welcome_msg_id
FROM wk
,employees ee
,MEMBER_ENROLLMENTS me
,plans pl
,( SELECT employee_id
,plan_type_id
,start_date
,plan_id
,MIN(MEMBER_ENROLLMENT_ID) member_enrollment_id
FROM ( SELECT me.employee_id
,DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id
,pl.start_date
,wk.plan_id
,me.member_enrollment_id
FROM wk
,PLANS pl
,MEMBER_ENROLLMENTS me
WHERE wk.done_by = nvl('TEST' ,wk.done_by)
AND wk.welcome_msg_name <> 'NONE'
AND pl.employer_id = wk.employer_id
AND wk.employer_id = 5
AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
AND pl.plan_id = NVL(wk.plan_id,pl.plan_id)
AND me.plan_id = pl.plan_id
AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
MINUS
SELECT me.employee_id
,DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id
,pl.start_date
,NULL plan_id
,me.member_enrollment_id
FROM wk
,PLANS pl
,MEMBER_ENROLLMENTS me
WHERE wk.done_by = nvl(NULL,wk.done_by)
AND wk.welcome_msg_name <> 'NONE'
AND pl.employer_id = wk.employer_id
AND wk.employer_id = 5
AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
AND pl.plan_id = wk.plan_id
AND me.plan_id = pl.plan_id
AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
WHERE employee_id = 100
GROUP BY employee_id ,plan_type_id,start_date ,plan_id
)first_enr
,MEMBER_EVENTS mv
WHERE wk.done_by = nvl(NULL,wk.done_by)
AND wk.employer_id = ee.employer_id
AND ee.employee_id = me.employee_id
AND ee.employee_id = 100
AND me.plan_id = pl.plan_id
AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
AND is_expired(me.employee_id,me.plan_id) = 'Y'
AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
AND pl.plan_id=nvl(wk.plan_id,pl.plan_id)
AND me.employee_id = first_enr.employee_id
AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = first_enr.plan_type_id
AND pl.start_date = first_enr.start_date
AND me.member_enrollment_id = mv.member_enrollment_id (+)
AND 'WELCOMEMSG' = mv.event_name(+)
AND mv.member_enrollment_id IS NULL
AND wk.welcome_msg_name <> 'NONE'
AND NVL(first_enr.plan_id,0) = NVL( wk.plan_id,0)
AND (FN_get_all_participant(wk.employer_id) = 1
OR
(FN_get_all_participant(wk.employer_id) = 0
AND (CASE WHEN pl.plan_type_id IN (1,2)
THEN NOT EXISTS (SELECT 'X'
FROM member_accounts ma
member_enrollments men3
plans pl3
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = me.employee_id
AND ma.plan_id = pl3.plan_id
AND pl3.start_date < pl.START_DATE
AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id in (1, 2)
UNION
(SELECT 'X'
FROM member_accounts ma
member_enrollments men3
plans pl3
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = me.employee_id
AND ma.plan_id = pl3.plan_id
AND pl3.start_date = (pl.start_date - 365)
\ AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id = wk.plan_type_id
UNION
(SELECT 'X'
FROM member_accounts ma
member_enrollments men3
plans pl3
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = men2.employee_id
AND ma.plan_id = pl3.plan_id
AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id = 2
UNION
(SELECT 'X'
FROM member_accounts ma
member_enrollments men3
plans pl3
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = men2.employee_id
AND ma.plan_id = pl3.plan_id
AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id = 1
WHEN pl.plan_type_id IN (3, 4)
THEN NOT EXISTS (SELECT 'X'
FROM member_accounts ma
member_enrollments men3
plans pl3
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = men2.employee_id
AND nvl(ma.account_end_date, sysdate) <= trunc(sysdate)
AND ma.plan_id = pl3.plan_id
AND pl3.start_date <= pl2.START_DATE
AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id in (3, 4)
END
AND (CASE WHEN pl.plan_type_id IN (1,2)
ERROR at line 89:
ORA-00936: missing expressionMaybe
SELECT ee.employee_id,
'WELCOMEMSG',
DECODE(me.member_enrollment_id,first_enr.enrollment_id,20,23) status_id,
me.member_enrollment_id,
wk.welcome_msg_id
FROM wk,
employees ee,
MEMBER_ENROLLMENTS me,
plans pl,
(SELECT employee_id,
plan_type_id,
start_date,
plan_id,
MIN(MEMBER_ENROLLMENT_ID) member_enrollment_id
FROM (SELECT me.employee_id,
DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id,
pl.start_date,
wk.plan_id,
me.member_enrollment_id
FROM wk,
PLANS pl,
MEMBER_ENROLLMENTS me
WHERE wk.done_by = nvl('TEST',wk.done_by) /* same as wk.done_by = 'TEST' */
AND wk.welcome_msg_name 'NONE'
AND pl.employer_id = wk.employer_id
AND wk.employer_id = 5
AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
AND pl.plan_id = NVL(wk.plan_id,pl.plan_id)
AND me.plan_id = pl.plan_id
AND me.coverage_effective_date != NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date,me.coverage_effective_date + 1)
MINUS
SELECT me.employee_id,
DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id,
pl.start_date,
NULL plan_id,
me.member_enrollment_id
FROM wk,
PLANS pl,
MEMBER_ENROLLMENTS me
WHERE wk.done_by = nvl(NULL,wk.done_by) /* same as 1 = 1 */
AND wk.welcome_msg_name 'NONE'
AND pl.employer_id = wk.employer_id
AND wk.employer_id = 5
AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
AND pl.plan_id = wk.plan_id
AND me.plan_id = pl.plan_id
AND me.coverage_effective_date NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
WHERE employee_id = 100
GROUP BY employee_id,
plan_type_id,
start_date,
plan_id
) first_enr,
MEMBER_EVENTS mv
WHERE wk.done_by = nvl(NULL,wk.done_by)
AND wk.employer_id = ee.employer_id
AND ee.employee_id = me.employee_id
AND ee.employee_id = 100
AND me.plan_id = pl.plan_id
AND me.coverage_effective_date != NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
AND is_expired(me.employee_id,me.plan_id) = 'Y'
AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
AND pl.plan_id = nvl(wk.plan_id,pl.plan_id)
AND me.employee_id = first_enr.employee_id
AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = first_enr.plan_type_id
AND pl.start_date = first_enr.start_date
AND me.member_enrollment_id = mv.member_enrollment_id(+)
AND 'WELCOMEMSG' = mv.event_name(+)
AND mv.member_enrollment_id IS NULL
AND wk.welcome_msg_name != 'NONE'
AND NVL(first_enr.plan_id,0) = NVL(wk.plan_id,0)
AND (
FN_get_all_participant(wk.employer_id) = 1
OR
(FN_get_all_participant(wk.employer_id) = 0
AND NOT EXISTS(SELECT 'X'
FROM member_accounts ma,
member_enrollments men3,
plans pl3,
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = me.employee_id
AND ma.plan_id = pl3.plan_id
AND pl3.start_date < pl.START_DATE
AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id in (1,2)
and pl.plan_type_id IN (1,2)
UNION
SELECT 'X'
FROM member_accounts ma,
member_enrollments men3,
plans pl3,
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = me.employee_id
AND ma.plan_id = pl3.plan_id
AND pl3.start_date = (pl.start_date - 365)
AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id = wk.plan_type_id
and pl.plan_type_id IN (1,2)
UNION
SELECT 'X'
FROM member_accounts ma,
member_enrollments men3,
plans pl3,
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = men2.employee_id
AND ma.plan_id = pl3.plan_id
AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id = (1,2)
and pl.plan_type_id IN (1,2)
UNION
SELECT 'X'
FROM member_accounts ma,
member_enrollments men3,
plans pl3,
plan_types pt3
WHERE ma.member_account_id = men3.member_account_id
AND ma.employee_id = men2.employee_id
AND trunc(nvl(ma.account_end_date,sysdate)) <= trunc(sysdate)
AND ma.plan_id = pl3.plan_id
AND pl3.start_date <= pl2.START_DATE
AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
AND pl3.plan_type_id = pt3.plan_type_id
AND pt3.plan_type_id in (3,4)
and pl.plan_type_id IN (3,4)
)Regards
Etbin -
Using different hierarchy in a query and last value error
Hi guys,
there is a hierarchy for customers in the 0Customer Infoobject which I should use in my query.
I have activated the hierarchy in the query and now some results are not appearing but red crosses "x" are shown.
And the error message: The function Calculate Results as ... could not be applied everywhere.
I know that I am using the result as "last value" for some columns because I need them there (for example: to determine the last value for the credit limit of the current month). I think these columns where I am using the last value calculation are only affected.
I mean my query has a lot of characteristics and key figures and I was told that a hiearchy for customers which is available should be used. But now there are these red crosses.
I don´t see any other solution as not to use this specific hierarchy.
Has anybody a suggestion what could be an argument to use or not to use a hierarchy?
Is it sometimes like in my case that a hierarchy is not possible to use?
Thanks in advance!Hi,
say for example your customer hierarchy is customers grouped under region. You can maintain this region as one of the attribute of customer and you can display this attribute in the report. Indirectly, this will give similar output to that of hierarchy.
But lot depends on how your hierarchy is formed, before commenting whether it can be moved to master data attributes.
Thanks. -
Excel and CASE statement.
Hello Experts,
I am using a CASE statement on CHAR column as follows:
CASE WHEN Sales.Ret='Y' THEN 'Returning' ELSE 'New' END
It gives an error: Odbc driver returned an error (SQLExecDirectW).
Whereas when I use another CASE statement with Numrical column it is working perfectly.
CASE WHEN Sales.Amount<40 THEN 40 ELSE 100 END
Am i missing some Excel data source setting related to CHAR data type?
My source is MS Excel 2003 and OBIEE is 10.1.3.4.1
Appreciate any comment, help.
~ Ash
PS: The error details are as follows:*
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: 37000 code: -3100 message: [Microsoft][ODBC Excel Driver] Syntax error (missing operator) in query expression 'case when T46.[Ret] = 'Y' then 'Returning' else 'New' end'.. [nQSError: 16014] SQL statement preparation failed. (HY000)
SQL Issued: SELECT Sales.Tran_date saw_0, CASE WHEN Sales.Ret='Y' THEN 'Returning' ELSE 'New' END saw_1, Network."Network Name" saw_2, Sales.Amount saw_3 FROM P4UD ORDER BY saw_0, saw_1, saw_2Hello Saichand,
I would like to reconfirm that the CASE statement with Numeric column is working with EXCEL as source.
The strange thing is that the CASE statement with CHAR column was also working! and from one fine day it it started throwing an error (i thought some source setting might got changed inadvertently ).
Thank you for your response but I would like to see comments/suggestions from other experts..
~ Ash
Edited by: OBIEE_Ash on Dec 20, 2010 10:27 PM -
SAP Query and selection screen fields
Hi,
I am currently modifying a Query. I have added a new selection field. The fieldname for this selection field has been autogenerated within the query and I have pasted a bit in here:
SELECT-OPTIONS SP$00015 FOR ZERROR_FLG LOWER CASE.
SELECT-OPTIONS SP$00022 FOR KNA1-ERDAT.
SELECT-OPTIONS SP$00023 FOR KNA1-ERNAM.
SELECT-OPTIONS SP$00027 FOR ZLOEVM LOWER CASE.
SELECT-OPTIONS SP$00030 FOR ZPARTNERNO
NO INTERVALS NO-EXTENSION.
I relation to this select -option, I want to execute a few lines of code that only is executed if the user has filled in a value in teh ZPARTNERNO field. However, no matter if I use the field name ZPARTNERNO or SP$00030 it has no effect.
Any good ideas ?HI,
In the AT SELECTIOn-SCREEN event, you can write the code
IF not <b>SP$00030[]</b> is initial.
write the code which you want to execute before the output
ENDIF.
if you want in START-OF-SELECTION>
IF not <b>SP$00030[]</b> is initial.
write the code which you want to execute before the output
ENDIF
Regards
Sudheer -
What is the diff between ABAP Query and SAP quary?
Balu,
SAP Query
Purpose
The SAP Query application is used to create lists not already contained in the SAP standard system. It has been designed for users with little or no knowledge of the SAP programming language ABAP. SAP Query offers users a broad range of ways to define reporting programs and create different types of reports such as basic lists, statistics, and ranked lists.
Features
SAP Query's range of functions corresponds to the classical reporting functions available in the system. Requirements in this area such as list, statistic, or ranked list creation can be met using queries.
All the data required by users for their lists can be selected from any SAP table created by the customer.
To define a report, you first have to enter individual texts, such as titles, and select the fields and options which determine the report layout. Then you can edit list display in WYSIWYG mode whenever you want using drag and drop and the other toolbox functions available.
ABAP Query, as far as I Believe, is the use of select statements in the ABAP Programming. This needs a knowledge of Open SQL commands like Select,UPdtae, Modify etc. This has to be done only by someone who has a little bit of ABAP experience.
To sum up, SAP queries are readymade programs given by SAP, which the user can use making slight modification like the slection texts, the tables from which the data is to be retrieved and the format in which the data is to be displayed.ABAP queries become imperative when there is no such SAP query existing and also when there is a lot of customizing involved to use a SAP Query directly.
Check out these links.
http://help.sap.com/saphelp_46c/helpdata/en/35/26b413afab52b9e10000009b38f974/content.htm
http://www.thespot4sap.com/Articles/SAP_ABAP_Queries_Introduction.asp
Step-by-step guide for creating ABAP query
http://www.sappoint.com/abap/ab4query.pdf
ABAP query is mostly used by functional consultants.
Kindly reward points by clicking the star on the left of reply,if it helps.Kindly close your previous threads if your problem is solved and reward points for helpful answers.
Don't forget to reward if useful... -
Creating t.code for ABAP query and Transport it TO Production and run it .
Hi Friends
Thanks for ur reply ,
The requirement is that i want to create tcode for abap query and that query can be regenearted ,
in case of regeneration programe name i got answer programame name will be change, i created and modified query but i saw the same programe name ,,, may be it changed when it is trasnported if so then what ??
and also pls give me solution for asiging tcode for query which is going to be regenerated.
thanks and regards
farukhDear Farukh,
As we know,
Query is created in Production server and a corresponding program is generated by System.
What we have to do is just to assign the program to the desired transaction code in Development server and transport it.
If you have any doubts please let me know.
Kindly assign points if you find this info usefull.
Regards,
Lijo Joseph -
Complex request with range filter and boolean search
Hi
I need a build and maintain complex requests to Oracle Endeca Server. These requests could include different types of attributes: string, datetime, int.
For string attributes I have created a search interface and use boolean search. For datetime attributes I use a range filter. Separately it works as I expected, but it fails with combined search with range filter and boolean search in a single request. As I see from results range filter is completely ignored. What could be wrong with following request?
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:Request xmlns:ns2="http://www.endeca.com/MDEX/lql_parser/types" xmlns:ns3="http://www.endeca.com/MDEX/conversation/1/0">
<ns3:State/>
<ns3:Operator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:RecordFilterOperator">
<ns3:RecordFilter Name="OnlyData">AND(NOT(mdex-property_Key),NOT(mdex-dimension_Key),NOT(mdex-config_Key),NOT(mdex-precedenceRule_Key),NOT(system-group_Key),NOT(system-group-membership_Key))</ns3:RecordFilter>
</ns3:Operator>
<ns3:Operator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:SortOperator" Direction="Descending" Key="string_prop" OwnerId="Records"/>
<ns3:Operator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:RangeFilterOperator">
<ns3:RangeFilter AttributeName="dateTime_prop">
<ns3:LowerBound Inclusive="true">2012-07-24T19:47:01Z</ns3:LowerBound>
</ns3:RangeFilter>
</ns3:Operator>
<ns3:Operator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:SearchOperator">
<ns3:SearchFilter SnippetLength="20" EnableSnippeting="true" Mode="Boolean" Key="orderSearch">multiple_prop : one</ns3:SearchFilter>
</ns3:Operator>
<ns3:ContentElementConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:RecordListConfig" HandlerFunction="RecordListHandler" HandlerNamespace="http://www.endeca.com/MDEX/conversation/1/0" Id="Records">
<ns3:RecordsPerPage>3</ns3:RecordsPerPage>
</ns3:ContentElementConfig>
</ns3:Request>
</S:Body>
</S:Envelope>
If my approach is incorrect could you provide me a a better way to handle such requests?
Regards,
Eugene.Hi Eugene,
As you know, this issue has been discussed further, so I am posting here the summary of the findings, with the hope that this summary will benefit the Endeca Server user community at large.
* Boolean search only works with range filters for the AND operator. The documentation link above confirms this.
*Because of this restriction, you need to build another query that would achieve the same result. Both options are equally good and would achieve the results you need. Two suggestions that we've received were:
- Option 1. You could perform the key restriction of the search via a restrictive search interface rather than using the boolean match mode. This would involve creating a search interface for each field and then querying against the search interface for the field in question:
<Operator xmlns="http://www.endeca.com/MDEX/lql_parser/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="SearchOperator">
<SearchFilter SnippetLength="20" EnableSnippeting="true" Mode="All" Key="orderSearch_for_field_multiple_prop">one</SearchFilter>
</Operator>
For this option, you would have to create a search interface for each attribute, using the Config Web Service. Here is the topic about loading config documents into the Endeca Server:http://docs.oracle.com/cd/E29805_01/server.230/es_dev/toc.htm#Loading%20configuration%20documents
- Option 2
* You could implement the range filter through EQL row expression syntax instead and pass it in via the DataSourceFilterOperator, which acts as a prefilter on all other query logic, using the Conversation Web Service. Thus you might include:
<Operator xmlns="http://www.endeca.com/MDEX/lql_parser/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="DataSourceFilterOperator">
<DataSourceFilterString>dateTime_prop <= TO_DATETIME('2012-07-24T19:47:01Z')</DataSourceFilterString>
</Operator>
For this option, using the DataSourceFilter does not require you to model the rest of the query in EQL. It will perform slightly better than the filter in option 1 because of the order in which record set intersections are computed, but the difference is likely to be very small.
Finally, if this addresses your question, please mark this question as answered, so that others can benefit from it on the forum. Big thanks to Endeca Server development team (you know who you are!), for helping to find solutions for this request.
Julia
Edited by: JuliaM on Aug 30, 2012 2:05 PM
Edited by: JuliaM on Aug 30, 2012 2:06 PM -
Diff between sap query and abap query
diff between sap query and abap query
Hi,
ABAP query is mostly used by functional consultants.
SAP Query :
Purpose
The SAP Query application is used to create lists not already contained in the SAP standard system. It has been designed for users with little or no knowledge of the SAP programming language ABAP. SAP Query offers users a broad range of ways to define reporting programs and create different types of reports such as basic lists, statistics, and ranked lists.
Features
SAP Query's range of functions corresponds to the classical reporting functions available in the system. Requirements in this area such as list, statistic, or ranked list creation can be met using queries.
All the data required by users for their lists can be selected from any SAP table created by the customer.
To define a report, you first have to enter individual texts, such as titles, and select the fields and options which determine the report layout. Then you can edit list display in WYSIWYG mode whenever you want using drag and drop and the other toolbox functions available.
ABAP Query,:
As far as I Believe, is the use of select statements in the ABAP Programming. This needs a knowledge of Open SQL commands like Select,UPdtae, Modify etc. This has to be done only by someone who has a little bit of ABAP experience.
To sum up, SAP queries are readymade programs given by SAP, which the user can use making slight modification like the slection texts, the tables from which the data is to be retrieved and the format in which the data is to be displayed.ABAP queries become imperative when there is no such SAP query existing and also when there is a lot of customizing involved to use a SAP Query directly
use either SQ02 ans SQ01
or SQVI tr code
for more information please go thru this url:
http://www.thespot4sap.com/Articles/SAP_ABAP_Queries_Create_The_Query.asp
http://goldenink.com/abap/sap_query.html
Please check this PDF document (starting page 352) perhaps it will help u.
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVQUE/BCSRVQUE.pdf
check the below link will be helpful for u
Tutorial on SQVI
once you create query system generates a report starting with AQZZ/SAPQUERY/ABAGENCY2======= assing this report to tr code for the same
regards,
vasavi.
reward if it is helpful.
Maybe you are looking for
-
Templates not locking correctly
Hi All, I have a site that using a DreamWeaver CS3 template as the base of the overall structure of the site. The live dev area using the template can be found at http://www.otsmanagement.com.au/dev The template uses only one editable region which is
-
Dear SDNers, Below are the questions that I have got when learning BO. SO Please answer these to help me out. We are having query and Calc Engine, Business layer and data foundation layer and Data federation engine in Universe . Business layer and Da
-
Oracle 11g Certification and Workshop Requirement
Hello, I have recently cleared below Oracle Exams. 1Z0-051 (SQL Fundamentals) 1Z0-052 (Oracle 11g Admin I) 1Z0-053 (Oracle 11g Admin II) - Cleared in May 2013 I haven't completed the Workshop requirement which indicates I am not OCP as of now. Questi
-
Blurry font on Keynote Printout
Hi, I'm a relatively new Apple user and am testing Keynote. I'm a college student, and many of my instructors post slides online, so I will print them out and take notes on them in class. Previously I would do this in Microsoft Word on my other compu
-
Writing to files - adding to existing file
hi, i am trying to write some additional text to a file, how do i do this. FileWriter fw=null; PrintWriter pw=null; try { fw = new FileWriter ("c:\\javanash.txt"); pw = new PrintWriter(fw); pw.println("pepper is at the door"); pw.close(); catch (IOEx