Query creation problem

Hi, I need to create a query that returns a cursor to a web client. The cursor must return 3 columns from a query, so that it can display a list of tick boxes. The tickboxes have 3 states:- visible, enabled, and selected.
In my example, I need to return a cursor so that it can display all 3 possible screens (i.e. sales, purchase, admin), for each of these screens a method of identifying whether the role allows the tick box to be enabled, and finally a method of ticking (selecting) the tick box according to the dept_id.
So far i have this, which does everything i need it to do, except for identifying whether to tick the box.
WITH screen AS
(SELECT 1 id, 'sales'    screen_desc, 103 dept_id,  501 role_id from dual union all
SELECT 2 id, 'purchase' screen_desc, 101 dept_id,  503 role_id from dual union all
SELECT 3 id, 'admin'    screen_desc, 103 dept_id,  503 role_id from dual ),
dept AS
(SELECT 101 id, 'marketing' dept_desc from dual union all
SELECT 102 id, 'management' dept_desc from dual union all
SELECT 103 id, 'IT' dept_desc from dual ),
role AS
(SELECT 501 id, 'junior'     role_desc from dual union all
SELECT 502 id, 'supervisor' role_desc from dual union all
SELECT 503 id, 'manager'    role_desc from dual)
select DISTINCT screen_desc, 'Y' enabled /*,'N' selected*/ from screen,dept,role
where dept.id        = screen.dept_id
AND   role.id        = screen.role_id
AND   dept_desc      = 'IT'
AND   role.role_desc = 'manager'
UNION
(select DISTINCT screen_desc, 'N' enabled/*, 'N' selected*/ from screen,dept,role
where dept.id       = screen.dept_id
AND   role.id       = screen.role_id
MINUS
select DISTINCT screen_desc, 'N' enabled/*, 'N' selected*/ from screen,dept,role
where dept.id        = screen.dept_id
AND   role.id        = screen.role_id
AND   dept_desc      = 'IT'
AND   role.role_desc = 'manager')Can anybody understand what i'm after, and secondly return the results i require, with the tables provided (i can't change the table relationships).
ta
David

Well this is what I get
SQL> WITH screen AS
  2  (SELECT 1 id, 'sales'    screen_desc, 103 dept_id,  501 role_id from dual union all
  3   SELECT 2 id, 'purchase' screen_desc, 101 dept_id,  503 role_id from dual union all
  4   SELECT 3 id, 'admin'    screen_desc, 103 dept_id,  503 role_id from dual )
  5  dept AS
  6  (SELECT 101 id, 'marketing' dept_desc from dual union all
  7   SELECT 102 id, 'management' dept_desc from dual union all
  8   SELECT 103 id, 'IT' dept_desc from dual ),
  9  role AS
10  (SELECT 501 id, 'junior'     role_desc from dual union all
11   SELECT 502 id, 'supervisor' role_desc from dual union all
12   SELECT 503 id, 'manager'    role_desc from dual)
13   select DISTINCT screen_desc, 'Y' enabled ,decode (dept_desc, 'IT', 'Y','N') selected from screen,dept,role
14   where dept.id        = screen.dept_id
15   AND   role.id        = screen.role_id
16   AND   dept_desc      = 'IT'
17   AND   role.role_desc = 'manager'
18  UNION
19  (select DISTINCT screen_desc, 'N' enabled, decode (dept_desc, 'IT', 'Y','N') selected from screen,dept,role
20   where dept.id       = screen.dept_id
21   AND   role.id       = screen.role_id
22  MINUS
23  select DISTINCT screen_desc, 'N' enabled, decode (dept_desc, 'IT', 'Y','N') selected from screen,dept,role
24   where dept.id        = screen.dept_id
25   AND   role.id        = screen.role_id
26   AND   dept_desc      = 'IT'
27   AND   role.role_desc = 'manager')
28  /
SCREEN_D E S
admin    Y Y
purchase N N
sales    N Y
SQL>So either your test data doesn't tie up the way you think it does, or you need to rework the precedence of your set operators.
By the way, the DISTINCTs are unnecessary - UNION gives your unique values anyway.
Cheers, APC
http://radiofreetooting.blogspot.com

Similar Messages

  • Could anyone provide the complete manual of SAP Query Creation

    Hi,
    Now I am learning to create SAP Query.
    I viewed many questions and answers about SAP Query.
    Some mentioned this,and some did that...
    Could anyone provide a complete manual of SAP Query Creation for developers.
    I can create SAP Queries step by step with it.

    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.
    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
    useful
    http://www.erpgenie.com/abap/code/abap47.htm
    regards,
    Prabhu
    reward if it is helpful

  • About query related problem

    hi ,
           we are generate query in 2005b,and procced for execuite query.following problem occure'<b>odbc sql server driver'[sql server] syntax error the converting the nvarchar value' 70302/20307' to column of data type int received alert OAIB</b>
    QUERY SHOWN BE AS FOLLOW.
    SELECT T5.DocNum as'Po. No. ', T5.DocDate as 'Po Date',T0.CreateDate,T5.NumAtCard as 'Man.PO. No/ Dt.', T0.DocNum as'AP No. ', T0.DocDate as 'AP Date',T0.NumAtCard as 'Vendor Ref. No.', T0.U_vbdt as 'Vendor Ref. Date', T0.CardName as 'Vendor', T1.Dscription as 'Item',  T1.Quantity AS 'QTY'  , T1.Price as 'Basic Rate', (T1.Price *T1.Quantity) as 'Value',T0.Comments as 'Po No. & Po.Dt.' FROM OPCH T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN OPDN T3 ON T2.CardCode = T3.CardCode INNER JOIN PDN1 T4 ON T3.DocEntry = T4.DocEntry INNER JOIN OPOR T5 ON T2.CardCode = T5.CardCode INNER JOIN POR1 T6 ON T5.DocEntry = T6.DocEntry INNER JOIN OITM T7 ON T1.ItemCode = T7.ItemCode INNER JOIN OITB T8 ON T7.ItmsGrpCod = T8.ItmsGrpCod WHERE (  T1.BaseRef  =  T3.DocNum )  AND ( T4.BaseRef =  T5.DocNum ) AND (  T0.U_vbdt >=[%25]AND  T0.U_vbdt <=[%26]) AND ( T4.Dscription =T1.Dscription ) AND ( T4.Dscription = T6.Dscription  ) AND  (( T1.Dscription=[%0] OR T1.Dscription=[%1] OR T1.Dscription=[%2] OR T1.Dscription=[%3] OR T1.Dscription=[%4] OR T1.Dscription=[%5] OR T1.Dscription=[%6] OR T1.Dscription=[%7] OR T1.Dscription=[%8] ) OR ( T0.CardName=[%10] OR T0.CardName=[%09] OR T0.CardName=[%27] OR T0.CardName=[%28] ) OR ((  T8.ItmsGrpNam =[%11]  oR T8.ItmsGrpNam =[%12] OR T8.ItmsGrpNam =[%13] OR T8.ItmsGrpNam =[%14] OR T8.ItmsGrpNam =[%15] OR T8.ItmsGrpNam =[%16] OR T8.ItmsGrpNam =[%17] OR T8.ItmsGrpNam =[%18] OR T8.ItmsGrpNam =[%19] ) and  ( T7.U_FirmName =[%20] OR T7.U_FirmName =[%21] OR T7.U_FirmName =[%22] 
    oR T7.U_FirmName =[%23] OR T7.U_FirmName =[%24] )) )

    Hi Vishal,
    the value '70302/20307' is not an whole number so converting it to an int is not possible.
    You should check your data for this value an change your query or data.
    Regards
    Ad

  • Query designing problem while applying cell properties

    Hello Experts,
    I have a problem while designing query. Problem is as follow:
    I have a calculated field on key figure column. This key figure calculates variance between 2 columns.
    for E.g I have 2 columns Budget and Actual and third column is %Variance which should be          
    1. ((Actual - Budget)/Budget) *100 or
    2. ((Budget -Actual)/Budget)*100, depening on some values on the row i should use any of these 2 formulas but the result should be dispalyed in single column % Variance.
    how can i change the formula in key figures depending on these conditions. I can achieve this by applying cells but i dont want to do so as it is very complex way to desing these queries.
    also let me know applying cells on query affects its performance or not?
    Regards,
    Nirav

    Hi Nitin,
    Your reply may help me.
    But my exact requirement is not that. Requirement is as follow:
    I have created Char. Structure in row which contains few rows as revenue and few rows as expense.
    I created them by creating selections. Now in case of expense the variance should be                (Budget-Actual)/Budget *100.
    In case of revenue variance should be (Actual-Budget)/Budget *100.
    So, here i have to find out revenue & expense char. iresspective of which one is greater.
    Regards,
    Nirav

  • Query has problem

    Below query has problem .
    Pls see the queries for Usage Summary with Partition and Without Partition
    . I have executed this now so it may be in Buffer …****
    DB Query ... SUM from event objects, bin variables
    SELECT sum(amount) , sum(quantity), event.poid_type,ebal.resource_id,****
    event.service_obj_type, event.service_obj_id0,ebal.
    rate_obj_id0, ebal.OFFERING_OBJ_ID0, ebal.IMPACT_CATEGORY ****
    FROM event_bal_impacts_t ebal, item_t item, event_tevent*
    WHERE event.item_obj_id0 = item.poid_id0****
    AND ebal.obj_id0 = event.poid_id0****
    --                   and event.Poid_id0 >= 266838277921701888****
    --                 and event.Poid_id0 < 267928993456455680****
    --               and ebal.obj_id0 >= 266838277921701888****
    --             and ebal.obj_id0 < 267928993456455680****
    AND item.bill_obj_id0 = 148715294****
    AND ebal.product_obj_id0 = 27433706****
    AND ebal.account_obj_id0 = 146876519****
    AND item.account_obj_id0 = 146876519****
    AND event.poid_type like '%session/telco/gsm%'****
    AND ebal.impact_category <> 'Free'****
    AND resource_id not in (select resource_id from
    resource_id_t)****
    group by****
    event.poid_type, ebal.resource_id,****
    event.service_obj_type, event.service_obj_id0,****
    ebal.rate_obj_id0, ebal.OFFERING_OBJ_ID0,ebal.
    IMPACT_CATEGORY****
    order by****
    ebal.resource_id desc;****
    SELECT sum(amount) , sum(quantity), event.poid_type,ebal.
    resource_id,****
    event.service_obj_type, event.service_obj_id0,ebal.
    rate_obj_id0, ebal.OFFERING_OBJ_ID0, ebal.IMPACT_CATEGORY ****
    FROM event_bal_impacts_t ebal, item_t item, event_tevent*
    WHERE event.item_obj_id0 = item.poid_id0****
    AND ebal.obj_id0 = event.poid_id0****
    and event.Poid_id0 >= 264199450015039488****
    and event.Poid_id0 < 265237388991660032****
    and ebal.obj_id0 >= 264199450015039488****
    and ebal.obj_id0 < 265237388991660032****
    AND item.bill_obj_id0 = 148715294****
    AND ebal.product_obj_id0 = 27433706****
    AND ebal.account_obj_id0 = 146876519****
    AND item.account_obj_id0 = 146876519****
    AND event.poid_type like '%session/telco/gsm%'****
    AND ebal.impact_category <> 'Free'****
    AND resource_id not in (select resource_id from
    resource_id_t)****
    group by****
    event.poid_type, ebal.resource_id,****
    event.service_obj_type, event.service_obj_id0,****
    ebal.rate_obj_id0, ebal.OFFERING_OBJ_ID0,ebal.
    IMPACT_CATEGORY****
    order by****
    ebal.resource_id desc;****
    --

    848478 wrote:
    Below query has problem .
    Pls see the queries for Usage Summary with Partition and Without Partition
    . I have executed this now so it may be in Buffer …****
    DB Query ... SUM from event objects, bin variables
    SELECT sum(amount) , sum(quantity), event.poid_type,ebal.resource_id,****
    event.service_obj_type, event.service_obj_id0,ebal.
    rate_obj_id0, ebal.OFFERING_OBJ_ID0, ebal.IMPACT_CATEGORY ****
    FROM event_bal_impacts_t ebal, item_t item, event_tevent*
    WHERE event.item_obj_id0 = item.poid_id0****
    AND ebal.obj_id0 = event.poid_id0****
    --                   and event.Poid_id0 >= 266838277921701888****
    --                 and event.Poid_id0 < 267928993456455680****
    --               and ebal.obj_id0 >= 266838277921701888****
    --             and ebal.obj_id0 < 267928993456455680****
    AND item.bill_obj_id0 = 148715294****
    AND ebal.product_obj_id0 = 27433706****
    AND ebal.account_obj_id0 = 146876519****
    AND item.account_obj_id0 = 146876519****
    AND event.poid_type like '%session/telco/gsm%'****
    AND ebal.impact_category <> 'Free'****
    AND resource_id not in (select resource_id from
    resource_id_t)****
    group by****
    event.poid_type, ebal.resource_id,****
    event.service_obj_type, event.service_obj_id0,****
    ebal.rate_obj_id0, ebal.OFFERING_OBJ_ID0,ebal.
    IMPACT_CATEGORY****
    order by****
    ebal.resource_id desc;****
    SELECT sum(amount) , sum(quantity), event.poid_type,ebal.
    resource_id,****
    event.service_obj_type, event.service_obj_id0,ebal.
    rate_obj_id0, ebal.OFFERING_OBJ_ID0, ebal.IMPACT_CATEGORY ****
    FROM event_bal_impacts_t ebal, item_t item, event_tevent*
    WHERE event.item_obj_id0 = item.poid_id0****
    AND ebal.obj_id0 = event.poid_id0****
    and event.Poid_id0 >= 264199450015039488****
    and event.Poid_id0 < 265237388991660032****
    and ebal.obj_id0 >= 264199450015039488****
    and ebal.obj_id0 < 265237388991660032****
    AND item.bill_obj_id0 = 148715294****
    AND ebal.product_obj_id0 = 27433706****
    AND ebal.account_obj_id0 = 146876519****
    AND item.account_obj_id0 = 146876519****
    AND event.poid_type like '%session/telco/gsm%'****
    AND ebal.impact_category <> 'Free'****
    AND resource_id not in (select resource_id from
    resource_id_t)****
    group by****
    event.poid_type, ebal.resource_id,****
    event.service_obj_type, event.service_obj_id0,****
    ebal.rate_obj_id0, ebal.OFFERING_OBJ_ID0,ebal.
    IMPACT_CATEGORY****
    order by****
    ebal.resource_id desc;****
    --Consider getting the asterisk key fixed, since it results in invalid SQL syntax

  • Query Creation

    Dear All ,
    This is regarding Query Creation.
    I want to create Query by Joinging Two tables.
    I have created User Group, Created Infoset,
    Now am creating Query by SQ01.
    Going Step by step correctly.
    I have Tick mark on Field group and selected .
    Then By next screen i have marked for option for Parameter.
    Then Clicked on "BasicList"  Button.
    Now after clicking Basic list button i am not getting screen of Basic list Line Structure
    i.e Scrren with detais like  with heading of type Field , Line ,Sequence, Sort Total etc. i am not getting.
    Instead, After Pressing BasicList button i am getting screen like Query ...... layout Design.
    So where /How cani get Scrren of Basic List Line struecture.
    In which menu / option i have to check.
    For Information we have SAP ECC 6. 0 with Application support Package no. 14.
    PL help me for my probelm
    Regards
    Swati

    Hello,
    I got solution of my probelm.
    Removed Tick  Marked from Menu option Settings --> Setting -
    > Here removed tick mark from Graphical Query Painter.
    Thanks to all.
    Regards
    Swati

  • Basic Query Creation

    Hello,
    Our company is about to go live with B1 and E commerce. We are very much looking forward to getting the ball rolling: the old MOM system and Sitelink shopping cart is causing issues!
    Anyway, before i go too much further i would like to get hold of some basic Query creation documentation. So far i have been unable to find any.
    If i have posted this in the wrong discussion group i apologies.
    I look forward to hearing your comments and becoming a regular in this group,
    Thanks,
    Charlie

    Hi Charlie,
    Beside this forum, you may also search and post here:
    SAP Add-Ons
    Thanks,
    Gordon

  • Failure to search - query window problem

    Hello again,
    Have anyone of you came across a problem with SAP search mechanism in query window attached to document field? I've created a simple query of "Select acctcode,acctname from OACT where acctcode like '2%' and postable='Y' order by acctcode" and attached it to one of document fields (doesn't matter which one). When I run this query a usual window poped up with a search field on the top, but when I typed "2" in it, selection bar moved right into first 231 account ignoring any of the lesser numbers. There is more - when I changed query to search for '5%' like accounts, I gained the same result - accounts less than 530 were ignored even if I typed "50" or "51". BUT - when I changed query sort order to "desc", all account became "findable".
    I got this problem in one database only which is SAP 8.8 PL10 version upgraded recently from 2007A one. I've checked with a newly created 8.8 and such problem hasn't occured.

    Hello Thomasz,
    I might be off base here, what happens when you use this??? 
    Do you get the same types of query window problem???
    Select
    acctcode,
    acctname,
    segment_0
    from OACT
    where Segment_0 like '2%'
    order by acctcode
    for browse
    Regards,
    Zal

  • Problem in new query creation

    Hi Experts,
    In a report there are two InfoObjects posting date and Expiry Date. User will enter the posting date at the run time. Now user wants to see the sales values for the conditions as below:-
    0<=|(Expiry Date-Billing Date)/30|<6
    6<|(Expiry Date-Billing Date)/30|<=12
    12<|(Expiry Date-Billing Date)/30|<=18
    18<|(Expiry Date-Billing Date)/30|<=24
    24<|(Expiry Date-Billing Date)/30|<=36
    36<|(Expiry Date-Billing Date)/30|<=48
    48<|(Expiry Date-Billing Date)/30|<=60
    Now question is when restricting the Expiry Date how to use value of Billing date. For example, say user gives Billing date=x. Now how to give restriction on Expiry date as x <(Expiry date)< x + 30*6.
    Any input will be highly appreciated.
    Thanks in advance.
    Regards,
    Prakash

    1st thing you need do is convert the Expiry Date, Billing Date into Key figures for that fallow below approach..
    http://www.sd-solutions.com/SAP-HCM-BW-Replacement-Path-Variables.html
    then create a formula for Expiry Date-Billing Date  , then you can include this formula in your conditions

  • Query Bex Problem

    Hi,
    I have a problem when I open a query Bex With 7.0 BW.
    There is a Analyzer Message Popup with this error:
    ! Creation of Item TEXTELEMENT_23 Failed
    ! Creation of Item TEXTELEMENT_2 Failed
    ! Creation of Item TEXTELEMENT_4 Failed
    ! Creation of Item TEXTELEMENT_5 Failed
    ! Creation of Item TEXTELEMENT_6 Failed
    ! Creation of Item TEXTELEMENT_7 Failed
    ! Creation of Item NAVPANEL13 Failed
    ! Creation of Item TEXTELEMENT_30 Failed
    After installation check there aren't problems.
    Excel Version is      11.0  8169 (001)
    Windows Version is     Windows XP Service Pack 2 (2600)
    SAP GUI 6.40 13 or higher
    Version on PC     7.00 Patch 1502
    This problem refers only to one PC CLient.
    On others PC there are no problem.
    Can you help me?
    Thanks.
    Davide

    Hi
    We have seen these issues when doing certain things when disconnected from BW, eg. renaming of excel tabs where the query is inserted etc. then you are likely to see this issue. 
    "The "new" 7.0 Analyzer works with a complete different paradigm
    than the "old" 3.X one - now an Excel sheet is seen as a "container"
    containing items (similar as in the WAD) whereas the old analyzer
    works more cell-oriented. Therefore a much stronger dependency now
    exists between the items and the sheet, and that's why you can't
    rename sheets when the Analyzer is not running.
    So in the end this means that we haven't "removed functionality"
    but due to a different implementation some things behave different
    or can't be used as in the older version."
    Hope this is of use.

  • Query rewrite problem related to FGAC/RLS/VPD

    My problem in related to Fine Grained Access Control / DBMS_RLS.
    Let's start with a simple example and elaborate further.
    Basic problem:
    Let's say we have two tables:
    create table LEVEL1( L1NR NUMBER not null, TAG NUMBER);
    alter table LEVEL1 add constraint LEVEL1_PK primary key (L1NR);
    create table LEVEL2( L1NR NUMBER, L2NR NUMBER not null);
    alter table LEVEL2 add constraint LEVEL2_PK primary key (L2NR);
    alter table LEVEL2 add constraint LEVEL2_FK foreign key (L1NR) references LEVEL1 (L1NR);
    I want to convince the database to rewrite a query that looks like this:
    A)
    SELECT L1.TAG, L2.L2NR
    FROM
    LEVEL2 L2
    INNER JOIN LEVEL1 L1
    ON L2.L1NR = L1.L1NR
    WHERE
    EXISTS( SELECT 1 FROM LEVEL1 L1B WHERE L1B.L1NR = L2.L1NR)
    As L2 will be joined to L1 for my human eye and mind
    it is obvious that the where clause is redundant,
    and the query is equivalent to:
    B)
    SELECT L1.TAG, L2.L2NR
    FROM
    LEVEL2 L2
    INNER JOIN LEVEL1 L1
    ON L2.L1NR = L1.L1NR
    Is there any way to convince the parser/optimizer to remove the redundant join?
    Why do I have a query like A) and why I cannot rewrite it myself I will explain below.
    For those to ask themselves why do I need such a thing let me elaborate.
    We develop an application and we want to enforce security on the data at the row level.
    The problem is more complicate than my following example, but the example is good enough.
    Let's say that we have an application that makes invoices.
    We want to give a user the privilege to make reports on the invoices issued for a category of customers.
    I see three main ways to enforce row level security on data:
    1) At the application level
    2) Using views
    3) Using Fine Grained Access Control / DBMS_RLS
    Choice 1) is more flexible, but it has a major drawback:
    You cannot make the database available for reporting with BI/ad-hoc reporting tools.
    And also you have to be careful with every query you write. Or create something that takes care of the security, which can be really tricky.
    And it also makes report creation for the application difficult since you need to embed the security system into the reporting module.
    If you use Crystal Reports or some other reporting tool to build your application report you've got a problem.
    Choices 2) and 3) are somewhat similar, but 3) is more flexible
    For those who don't know how FGAC/DBMS_RLS works and don't want to dig deeper here is a short explanation:
    DBMS_RLS allows the database developer to attach dynamic where clauses to queries.
    It does this by rewriting queries like:
    "select blabla from employees"
    to "select blabla from (select * from employees where <some expression that filters the data according to the user's policy>)"
    The filters are attached on a table by table basis, so queries like:
    SELECT dept.NAME, empl.NAME
    FROM
    DEPARTMENT dept
    INNER JOIN employees empl
    are rewritten to
    SELECT dept.NAME, empl.NAME
    FROM
    (SELECT * FROM DEPARTMENT WHERE <FILTER_DEPT>) dept
    INNER JOIN (SELECT * FROM employees WHERE <FILTER_EMP>) empl
    So far so good, nothing looks bad, but the devil is in the detail
    Back to our reporting problem.
    Let's say we have a scenario simpler than life, and I associate the user directly to a customer category by adding a CUST_CAT_ID column to the APP_USER table.
    I want restrict the user to see only the data associated to its category (category, customers, invoices, invoice item)
    So when he writes "select NAME, ADDRESS from customer" the query is rewritten to
    "select NAME, ADDRESS from (SELECT * FROM CUSTOMER WHERE (EXISTS SELECT 1 FROM category join app_user on ... where customer.CUST_CAT_ID = app_user.CUST_CAT_ID and app_user.login = get_current_user()))"
    where get_current_user is some framework function that gives me the current user.
    A little complicated, but nothing too scary.
    But when I write something like:
    SELECT <relevant columns> FROM category cat JOIN customer cust JOIN invoice inv JOIN invoice_item item WHERE <some filters>
    ...(query totally legitimate for a sales report), this gets expanded to a scary query that looks like this:
    SELECT <relevant columns>
    FROM
    (SELECT * FROM category WHERE (EXISTS SELECT 1 FROM app_user u WHERE u.CUST_CAT_ID = CAT_ID AND u.login = get_current_user())) cat
    JOIN (SELECT * FROM customer WHERE(EXITS SELECT 1 FROM category JOIN app_user WHERE ...)) cust
    JOIN (SELECT * FROM invoice WHERE(EXITS SELECT 1 FROM customer JOIN category JOIN app_user WHERE ...)) inv
    JOIN (SELECT * FROM invoice_item WHERE(EXITS SELECT 1 FROM invoice JOIN customer JOIN category JOIN app_user WHERE ...)) item
    WHERE
    <some filters>
    Oops! A query with 4 tables is expanded to a 14 tables query, when all I really need is:
    SELECT <relevant columns>
    FROM category cat JOIN customer cust JOIN invoice inv JOIN invoice_item item
    WHERE <some filters> AND (EXISTS SELECT 1 FROM app_user u WHERE u.CUST_CAT_ID = CAT_ID AND u.login = get_current_user())
    Let me tell you that we don't use here roles and privileges tables that we must use in a real life scenario.
    In a real life scenario we will easily transform the original query in a 20-30 table join (grrrrrrr).
    Well, I cannot change the way DBMS_RLS/FGAC works, and also if I choose to use views I cannot write a filtered view for every possible join that a user might create.
    All I want is to find out if there is any way to instruct the parser/optimizer, using primary and foreign keys, optimizer parameters hints and other methods, to rewrite the query and eliminate redundant joins.
    Of course I can create some materialized views or bitmap join indexes to help me in the process and speed up the query, but using this method in a database that has hundreds of tables can be a little problem in terms of management and performance.

    Hello again,
    It appeared that, the problem is present only when I try the query in pl/sql developer.
    For some reason, even though I set QUERY_REWRITE_INTEGRITY to STALE_TOLERATED, it behaved as this parameter was set to ENFORCED.
    So the case was that:
    for session - STALE_TOLERATED
    for system - ENFORCED
    In v$parameter2 against "QUERY_REWRITE_INTEGRITY" was shown "stale_tolerated", but the query was not rewritten.
    When I do the same (altering the session and perform the select query) in SQLPlus, everything works as expected - the query is rewritten.
    And I conclude the problem is in PL/SQL Developer (my version is 8.0.1.1498) or something related to this.
    Edited by: Verdi on 2010-2-12 14:00

  • Query help - problems with ROLLUP

    I'm trying to make a query i can use for an alert, it generates sales for the past 7 days.
    This query works fine:
    SELECT
          CASE WHEN GROUPING(T0.[CardCode]) = 0
                THEN CAST (T0.[CardCode] AS CHAR(8))
                ELSE 'ALL'
          END AS Customer#,
          SUM(T0.[Max1099]) AS "Total Sales",
          SUM(T0.[GrosProfit]) AS "Gross Profit" 
    FROM OINV T0
    WHERE T0.[DocDate] >= DATEADD(dd,DATEDIFF(dd,0,GETDATE())-7,0) AND T0.[Max1099] > 0
    GROUP BY T0.[CardCode] WITH ROLLUP
    And it gives me this:
    #     Customer#*     Total Sales*     Gross Profit*     
    1     C2235              8,285.87       4,165.77            
    2     C2236           10,191.39              4,197.95            
    3     C2253                570.56               311.17          
    4     C3008           18,756.76       5,720.21            
    5     ALL                   37,804.58    14,395.10            
    Which is great. Gives me a total at the end, and substitutes "ALL" for the customer number. Lovely.
    Problem #1: I REALLY want it to give the Customer Name NEXT TO the Customer Number. But when I try to add it, i have to add it to the GROUP BY as well. Which changes the query to this:
    SELECT
          CASE WHEN GROUPING(T0.[CardCode]) = 0
                THEN CAST (T0.[CardCode] AS CHAR(8))
                ELSE 'ALL'
          END AS Customer#,    
          CardName as "Cust Name",     
          SUM(T0.[Max1099]) AS "Total Sales",
          SUM(T0.[GrosProfit]) AS "Gross Profit"
    FROM OINV T0
    WHERE T0.[DocDate] >= DATEADD(dd,DATEDIFF(dd,0,GETDATE())-7,0) AND T0.[Max1099] > 0
    GROUP BY T0.[CardCode], T0.[CardName] WITH ROLLUP
    And changes my output to THIS:
    #     Customer#     Cust Name                             Total Sales     Gross Profit     
    1     C2235             Acme Products                      8,285.87               4,165.77     
    2     C2235          (blanks blanks)                        8,285.87               4,165.77     
    3     C2236             Some Other Products             10,191.39               4,197.95     
    4     C2236          (blanks blanks blanks)            10,191.39               4,197.95     
    5     C2253             Third Customer Name             570.56                  311.17     
    6     C2253          (blanks blanks blanks)                570.56                  311.17     
    7     C3008             Fourth Customer Name       18,756.76       5,720.21     
    8     C3008          (blanks blanks blanks)                                               18,756.76       5,720.21     
    9     ALL                                                                  37,804.58     14,395.10     
    ( I have replaced actual customer names, of course, and replaces actual blanks with the word 'blanks' so it would be more legible.)
    I can't figure out a way to simply list the customer name next to the number. Instead , it gives me a summary for the CardCode and a summary for the CardName.
    I've tried combining the two into one field, on the fly, but haven't been successful.
    Problem #2 - extra credit!
    If i really want this done right, i should also have a query that pulls the same data from ORIN (Credit Memos) and do a UNION ALL, but when i do this, is simply rejects me at the word "UNION"
    any and all help appreciated, and to test this, you can just cut and past the query into SAP, it will run right there, no mods needed.
    oops. I had to change the "Not Equal" symbol to just "greater than" for "Max1099" because it was just dropping the symbol...
    Edited by: Dante Amodeo on Jan 18, 2012 6:30 PM

    Try:
    SELECT CAST (T0.CardCode AS CHAR(8)) AS Customer#,
    MAX(T0.CardName) 'Customer Name',
    SUM(T0.Max1099) AS 'Total Sales',
    SUM(T0.GrosProfit) AS 'Gross Profit'
    FROM OINV T0
    WHERE DATEDIFF(dd,T0.DocDate,GETDATE())<=7 AND T0.Max1099 > 0
    GROUP BY T0.CardCode
    UNION ALL
    SELECT 'ALL','',SUM(T0.Max1099),
    SUM(T0.GrosProfit)
    FROM OINV T0
    WHERE DATEDIFF(dd,T0.DocDate,GETDATE())<=7 AND T0.Max1099 > 0

  • Database creation problem on Windows XP

    Hello Readers
    I have installed ORACLE Database Engine on windows XP.
    I am facing problem in database creation.
    I have tryed wizard as well as mannual method.
    in wizard at 90% it gives an error "END-OF-FILE ON COMMUNICATION CHANNEL"
    although CD drive is in CR Rom drive.
    Please help me ....
    Rashid Masood Ashraf
    email: [email protected]

    After going to the properties as you suggested:
    Right now the Obtain an IP address automatically is checked
    I need to check the Use the following IP address:
    What should I enter for
    IP address:
    Subnet mask:
    Default gateway:
    Please help.
    Edited by: Nel Marcus on Dec 2, 2008 3:49 PM

  • BI 7.0 Infoset query open problem: query_tech_name_Fxx is not a valid char.

    Our BASIS transport our BW 3.5 queries to BI 7.0 system.  We can open all queries on the BI 7.0 box without problem except Infoset queries.  The Infoset is composed of two ODSs and when openning it BI 7.0 query designer, can not see any design element in the panes of Rows, Columns, Free Char. and etc., instead the error msg shows (in between two dashed lines below):
    Terminate: query_technical_name_Fxx is not a valid characteristic for InfoProvider [A122(BRAIN)]
    Diagnosis
    Customer enhancement RSR00002 or the implementation of BAdI RSR_OLAB_BADI delivers query_technical_name_Fxx as the characteristic to be calculated. 1. is, however, not a valid key figure for InfoProvider .
    System Response
    The information from query_technical_name_Fxx is ignored.
    Procedure
    Check the exit.
    Procedure for System Administration
    We've checked the enhancement RSR00002 and it's components and find they are all the same as our BW 3.5 system.  query_technical_name_Fxx is Company Code InfoObj. in one ODS and it's one of the key to join these two InfoSets.
    Any idea?
    Thanks

    hi Kevin,
    check if helps following oss note
    Note 983449 - Termin A122 1COLUMN no valid characteristic of infoprovider
    Symptom
    Termination A 122 Brain occurs when you test and generate a query. The system does not recognise the characteristic 1COLUMN.
    Other terms
    Query, condition, COB_PRO
    Reason and Prerequisites
    This problem is caused by a program error.
    Solution
    SAP NetWeaver 2004s BI
               Import Support Package 10 for SAP NetWeaver 2004s BI (BI Patch 10 or SAPKW70010) into your BI system. The Support Package is available once Note 914304 "SAPBINews BI 7.0 Support Package 10", which describes this Support Package in more detail, has been released for customers.
    In urgent cases, you can implement the correction instructions.
    You must first implement Notes 932065, 935140, 948389, 964580 and 969846, which provide information about transaction SNOTE. Otherwise, problems and syntax errors may occur when you deimplement some notes.

  • The problem about  integrate  Portal and R/3 : vendor query report problem

    Hi everyone :
       We want to achieve that our vendor can query R/3 report via our Portal. I had done SSO configuration.
       But we had about 500 vendors, it is impossible that we create 500 R/3 users for our vendors,  because the cost is too much .
       And there is another problem, vendor who had the authorization to query report can query the other vendor's data at same time. But we expect that certain vendor can query his data only.
       I think this is a general problem when integrate Portal and R/3, BW .
       Is there somebody had solved this problem or give any advice?
       Any discuss is welcome.
    Best Regards,
    Jianguo Chen

    Hi,
    I would say: get in contact with your SAP account manager anc check which options SAP can offer you...
    Normally every user using a R/3 system has to have a valid user license in that system. Expecially when you want to access control to data on user (vendor) level you nedd to identifiy the user clearly and uniquely which by standard means you need a user for every vendor.
    Hth,
    Michael

Maybe you are looking for

  • My imovie won't open.  It's keeps crashing.

    I've reinstalled Ilife 2 times and it still wont work on my macbook? Any Ideas of what I can do?

  • Error while installing jdk1.5.07 on Windows 2000.(data1.cab file missing or

    I am unable to install jdk1.5.0.07/jdk1.5.0.11and while Copying files this error is generated. "Data1.cab file is missing or corrupt.". I have tried to download the same from Sun's download centre as offline installation. Please suggest a solution. R

  • Premiere Pro CC MXF problems

    Hi there, I'm currently working on Premiere Pro CC. We've imported all of our clips from our C300 from a hard drive that was shipped to us. The folder structure in intact and the clips have been working fine, up until now. I opened up my project toda

  • EasyDMS - How to create user groups?

    Hi, we are using ERP2005 and EasyDMS SP08(Unicode). We like to use user groups from the authorization tab to implement authorizations on folders and document. We can create a user group in EasyDMS, but if we assign this to a document it is said that

  • How to convert a webservice made out of BAPI to java?

    Hi All, There is typical requirement in our project where in we have to convert all the webservices that we made out of the BAPI's into java webservice. I understand that the wsdl file released is an XML file. But I don't understand like how to conve