Create a view using common table expressions

I'm having trouble finding out if this is even possible in Oracle.
Here is what I'm trying to accomplish with my view. A subject takes a survey numerous times across numerous dates. Depending on the responses to different questions, that subject is marked as having a set disease or affliction. The view that I'm building collects the necessary answers for each survey into one place (the first common table expression), then in subsequent CTEs, I'm adding the disease classification when the responses to the needed questions match. Sometimes the requirements state that the survey can't already be positive for other diseases, meaning that I need to ultimately discount them when checking subsequent diseases (each disease is built using it's own CTE of which there are 13). I built the query which performs these tasks with no problems. It runs and gives the responses that I'm looking for.
The problem comes into play when I attempt to wrap the existing working query into a create view process. When I add CREATE OR REPLACE VIEW TESTENV.TESTVIEW AS ( and the ending ); after the query, it is giving me the error: ORA-32034: unsupported use of WITH clause.
Am I getting the error simply because I can't put CTE's into views, or is it because the syntax for putting CTEs into Views is different than a normal view build process? Also, in case it makes a difference, the version of Oracle I'm using is: Oracle 10g.
Thank you.

Here is the view that I'm trying to build:
<pre class="jive-pre">
CREATE OR REPLACE VIEW GI_DEV.PAIN_COMP AS (
WITH gatheredQuestions AS (
SELECT
s.date_of_survey_id,
a.question_1 as A_1,
a.question_5 as A_5,
a.question_6 as A_6,
a.question_7 as A_7,
a.question_8 as A_8,
a.question_9 as A_9,
a.question_10 as A_10,
a.question_12 as A_12,
a.question_13 as A_13,
a.question_14 as A_14,
a.question_15 as A_15,
a.question_16 as A_16,
b.question_1 as B_1,
b.question_4 as B_4,
b.question_5 as B_5,
b.question_6 as B_6,
b.question_7 as B_7,
b.question_8 as B_8,
b.question_9 as B_9,
b.question_11 as B_11,
b.question_12 as B_12,
b.question_13 as B_13,
b.question_14 as B_14,
b.question_15 as B_15,
b.question_16 as B_16,
b.question_16a_a as B_16a_a,
b.question_16a_b as B_16a_b,
b.question_16a_c as B_16a_c,
b.question_16a_d as B_16a_d,
b.question_16a_e as B_16a_e,
b.question_16a_f as B_16a_f,
b.question_16b as B_16b,
c.question_1 as C_1,
c.question_2 as C_2,
c.question_3 as C_3,
c.question_8 as C_8,
c.question_9 as C_9,
c.question_10 as C_10,
c.question_11 as C_11,
c.question_11a as C_11a,
c.question_11b as C_11b,
d.question_1 as D_1,
d.question_2 as D_2,
d.question_3 as D_3,
d.question_4 as D_4,
d.question_5 as D_5,
d.question_5a as D_5a,
d.question_5b as D_5b,
d.question_5c as D_5c,
d.question_6 as D_6,
d.question_6a as D_6a,
d.question_6b as D_6b,
d.question_6c as D_6c,
d.question_6d as D_6d
FROM
new_date_of_survey s
LEFT OUTER JOIN new_section_a a on a.solid_visit_a_id = s.date_of_survey_id
LEFT OUTER JOIN new_section_b b on b.solid_visit_b_id = s.date_of_survey_id
LEFT OUTER JOIN new_section_c c on c.solid_visit_c_id = s.date_of_survey_id
LEFT OUTER JOIN new_section_d d on d.solid_visit_d_id = s.date_of_survey_id
), functDyspepsia as (
SELECT
date_of_survey_id,
'Functional Dyspepsia' as pain_type
FROM gatheredQuestions g
WHERE
g.A_1 in (4, 5)
and g.A_5 in (3, 4, 5, 6)
and g.A_6 in (0, 2, 3)
and (g.A_7 in (0, 2) and g.A_8 in (0,2))
and (g.A_9 in (0, 2) and g.A_10 in (0, 2))
), IBSLower as (
SELECT
date_of_survey_id,
'IBS Lower' as pain_type
FROM gatheredQuestions g
WHERE
g.B_1 in (3, 4, 5)
and g.B_4 in (2, 3, 4, 5, 6)
and 2 <= (CASE WHEN g.B_5 in (3, 4, 5) THEN 1 ELSE 0 END) + (CASE WHEN (g.B_6 in (3, 4, 5) and g.B_7 not in (3, 4, 5)) or (g.B_6 not in (3, 4, 5) and g.B_7 in (3, 4, 5)) THEN 1 ELSE 0 END) + (CASE WHEN (g.B_8 in (3, 4, 5) and g.B_9 not in (3, 4, 5)) or (g.B_8 not in (3, 4, 5) and g.B_9 in (3, 4, 5)) THEN 1 ELSE 0 END)
), IBSUpper as (
SELECT
date_of_survey_id,
'IBS Upper' as pain_type
FROM gatheredQuestions g
WHERE
g.A_1 in (3, 4, 5)
and g.A_5 in (3, 4, 5, 6)
and 2 <= (CASE WHEN g.A_6 in (3, 4, 5) THEN 1 ELSE 0 END) + (CASE WHEN (g.A_7 in (3, 4, 5) and g.A_8 not in (3, 4, 5)) or (g.A_7 not in (3, 4, 5) and g.A_8 in (3, 4, 5)) THEN 1 ELSE 0 END) + (CASE WHEN (g.A_9 in (3, 4, 5) and g.A_10 not in (3, 4, 5)) or (g.A_9 not in (3, 4, 5) and g.A_10 in (3, 4, 5)) THEN 1 ELSE 0 END)
), abMigraine as (
SELECT
date_of_survey_id,
'Abdominal Migraine' as pain_type
FROM gatheredQuestions g
WHERE
g.B_16 in (3, 4, 5)
and 2 <= ((CASE WHEN g.B_16a_a = 2 THEN 1 ELSE 0 END) + (CASE WHEN g.B_16a_b = 2 THEN 1 ELSE 0 END) + (CASE WHEN g.B_16a_c = 2 THEN 1 ELSE 0 END) + (CASE WHEN g.B_16a_d = 2 THEN 1 ELSE 0 END) + (CASE WHEN g.B_16a_e = 2 THEN 1 ELSE 0 END) + (CASE WHEN g.B_16a_f = 2 THEN 1 ELSE 0 END))
and g.B_16b = 2
), lowerFunctAbPainSyndrome as (
SELECT
date_of_survey_id,
'Functional Abdominal Pain Syndrome - Lower' as pain_type
FROM gatheredQuestions g
WHERE
g.B_1 in (4, 5)
and g.B_4 in (3, 4, 5, 6)
and date_of_survey_id not in (select date_of_survey_id from functDyspepsia union select date_of_survey_id from abMigraine union select date_of_survey_id from IBSLower union select date_of_survey_id from IBSUpper)
and
((g.B_15 in (2,3,4,5) and 2 > ((CASE WHEN g.B_11 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.B_12 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.B_13 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.B_14 in (2,3,4,5) THEN 1 ELSE 0 END)))
or (g.B_15 not in (2,3,4,5) and 2 <= ((CASE WHEN g.B_11 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.B_12 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.B_13 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.B_14 in (2,3,4,5) THEN 1 ELSE 0 END))))
), upperFunctAbPainSyndrome as (
SELECT
date_of_survey_id,
'Functional Abdominal Pain Syndrome - Upper' as pain_type
FROM gatheredQuestions g
WHERE
g.A_1 in (4, 5)
and g.A_5 in (3, 4, 5, 6)
and date_of_survey_id not in (select date_of_survey_id from functDyspepsia union select date_of_survey_id from abMigraine union select date_of_survey_id from IBSLower union select date_of_survey_id from IBSUpper)
and
((g.A_16 in (2,3,4,5) and 2 > ((CASE WHEN g.A_12 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.A_13 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.A_14 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.A_15 in (2,3,4,5) THEN 1 ELSE 0 END)))
or (g.A_16 not in (2,3,4,5) and 2 <= ((CASE WHEN g.A_12 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.A_13 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.A_14 in (2,3,4,5) THEN 1 ELSE 0 END) + (CASE WHEN g.A_15 in (2,3,4,5) THEN 1 ELSE 0 END))))
), lowerFunctAbPain as (
SELECT
date_of_survey_id,
'Functional Abdominal Pain - Lower' as pain_type
FROM gatheredQuestions g
WHERE
g.B_1 in (3, 4, 5)
and g.B_4 in (3, 4, 5, 6)
and date_of_survey_id not in (select date_of_survey_id from functDyspepsia union select date_of_survey_id from abMigraine union select date_of_survey_id from IBSLower union select date_of_survey_id from IBSUpper union select date_of_survey_id from upperFunctAbPainSyndrome union select date_of_survey_id from lowerFunctAbPainSyndrome)
), upperFunctAbPain as (
SELECT
date_of_survey_id,
'Functional Abdominal Pain - Upper' as pain_type
FROM gatheredQuestions g
WHERE
g.A_1 in (3, 4, 5)
and g.A_5 in (3, 4, 5, 6)
and date_of_survey_id not in (select date_of_survey_id from functDyspepsia union select date_of_survey_id from abMigraine union select date_of_survey_id from IBSLower union select date_of_survey_id from IBSUpper union select date_of_survey_id from upperFunctAbPainSyndrome union select date_of_survey_id from lowerFunctAbPainSyndrome)
), functConstipation as (
SELECT
date_of_survey_id,
'Functional Constipation' as pain_type
FROM gatheredQuestions g
WHERE
2 <= ((CASE WHEN g.C_1 in (0, 2) THEN 1 ELSE 0 END) + (CASE WHEN (g.C_2 in (2,3) and g.C_3 <> 2) or (g.C_2 not in (2, 3) and g.C_3 = 2) THEN 1 ELSE 0 END) + (CASE WHEN g.C_8 = 2 THEN 1 ELSE 0 END) + (CASE WHEN g.C_9 in (3, 4, 5) THEN 1 ELSE 0 END) + (CASE WHEN g.C_10 = 2 THEN 1 ELSE 0 END) + (CASE WHEN g.C_11 in (4, 5, 6) THEN 1 ELSE 0 END))
and date_of_survey_id not in (select date_of_survey_id from IBSLower union select date_of_survey_id from IBSUpper)
), fecalIncontinence as (
SELECT
g.date_of_survey_id,
'Nonretentive Fecal Incontinence' as pain_type
FROM
gatheredQuestions g
left outer join new_date_of_survey s on s.date_of_survey_id = g.date_of_survey_id
left outer join new_demographics d on d.solid_demographics_id = s.demo_id
WHERE
4 <= trunc((months_between(s.survey_date, d.date_of_birth))/12)
and g.C_11 in (4, 5, 6)
and g.C_11a in (2, 3)
and g.C_11b in (3, 4, 5, 6)
and g.date_of_survey_id not in (select date_of_survey_id from functConstipation)
), aerophagia as (
SELECT
date_of_survey_id,
'Aerophagia' as pain_type
FROM gatheredQuestions g
WHERE
2 <= ((CASE WHEN (g.D_1 in (3, 4, 5) and g.D_2 not in (3, 4, 5)) or (g.D_1 not in (3, 4, 5) and g.D_2 in (3, 4, 5)) THEN 1 ELSE 0 END) + (CASE WHEN g.D_3 in (3, 4, 5) THEN 1 ELSE 0 END) + (CASE WHEN g.D_4 in (3, 4, 5) THEN 1 ELSE 0 END))
), cycVomitSyndrome as (
SELECT
date_of_survey_id,
'Cycllic Vomiting Syndrome' as pain_type
FROM gatheredQuestions g
WHERE
g.D_5 in (4, 5)
and g.D_5a in (3, 4, 5, 6)
and g.D_5b = 2
and g.D_5c = 2
), adolRumSyndrome as (
SELECT
date_of_survey_id,
'Adolescent Rumination Syndrome' as pain_type
FROM gatheredQuestions g
WHERE
g.D_6 in (4, 5)
and g.D_6a = 2
and g.D_6b = 0
and g.D_6c = 0
and g.D_6d = 0
), gatheredPains as (
+
select * from functDyspepsia
union
select * from IBSLower
union
select * from IBSUpper
union
select * from abMigraine
union
select * from lowerFunctAbPainSyndrome
union
select * from upperFunctAbPainSyndrome
union
select * from lowerFunctAbPain
union
select * from upperFunctAbPain
union
select * from functConstipation
union
select * from fecalIncontinence
union
select * from aerophagia
union
select * from cycVomitSyndrome
union
select * from adolRumSyndrome
SELECT
date_of_survey_id,
string_agg(pain_type) as PainType
FROM gatheredPains
GROUP BY date_of_survey_id
</pre>
I tried remove the leading and ending parenthesis, and ended up getting the error that it is missing the select keyword. When I take the create view step out of this, the query builds with no problem, so I know that it's not missing a select or that it isn't in the correct place.
Thank you for all your help so far.

Similar Messages

  • Using Common Table Expressions in BO Universe

    Hi All,
    How to use Using Common Table Expressions(CTE) in BO Universe ?
    i created the stored procedure and tried to use it in universe but i'm not able to.
    Request you to help me out with this.
    Regards,
    Ravichandra K

    Did you get a chance to look at this guide chapter 7?
    [http://help.sap.com/businessobject/product_guides/boexir31/en/xi3-1_designer_en.pdf]
    Bashir Awan

  • Using Common Table Expressions (CTE) in a DSV Named Query

    Hi,
    I have a scenario where I need to "generate" fact data, so I'm using a CTE to generate the data. For maintainability reasons I have this CTE declared inside a view and in the DSV Named Query I just have a SELECT * FROM FactView.
    This works fine as long as the recursion level falls within the default limit of 100. If it does not, I have to specify the maximum recursion level such as:
    SELECT *
    FROM FactView
    OPTION (MAXRECURSION 0)
    The problem is I can't specify the Named Query like this. As explained elsewhere my query is embeded as a subquery and the OPTION keyword cannot be used in a subquery.
    Is there any other way I can specify the maximum recursion level on a Named Query?

    Load your fact table data into staging table and then process fact using direct load from staging table.

  • Extracting Metadata using Common Table Expressions MSSQL

    I have been using the below SQL query to extract subsets of the Metadata structure from several dimensions in HFM. The process works well and is simple/quick to develop and incorporate in existing processes. I am curious if anyone else has been using a similar query to extract subsets of HFM Structure directly from HFM or other approaches to extract a subset of HFM Structure.
    /*     The query starts with a "Top Parent" and will return all parent/child information below that member. For this example I want all the metadata for the c1 dimension so I am using the top most parent which by default has an ID of -1. You can look up and member's id in the "APP_DIM_Item" table and use that as the "Top Parent" for the query. It is possible to correctly extract only a subset of the overall metadata for each dimension.
    WITH dim (ItemID, ParentID, Level)
    AS
    SELECT
    el.ItemID
    ,el.[ParentID]
    ,0 AS Level
    FROM [<APP>CUSTOMLAYOUT] el     
    WHERE ParentID = -1 -- The "Top Parent" -1 will extract all metadata
              and lDimID = 1 -- Needed only for the custom dimensions.
    UNION ALL
    SELECT
         el.ItemID
    ,el.ParentID
    ,Level + 1 as Level
    FROM [ <APP>_CUSTOM_LAYOUT] el     
    INNER JOIN dim AS d
    ON el.ParentID = d.ItemID
    where el.lDimID = 1 -- needed for the custom dimensions
    /*     Once the structure is extracted to the temp dim table you can query back and
         join to the Item table to add addtional memeber details. If you leave the query as
         is you will only see the parent/child Unique ID and level informtaion.
    -- Parent/Child ID Structure
    SELECT * FROM dim
    -- Parent/Child Label Structure
    Select Dim.ItemID, Dim.ParentID, Dim.Level, Member.Label, Parent.Label
    From Dim
    inner JOIN <APP>CUSTOMITEM Member -- Member Detail
    on Member.ItemID = dim.ItemID AND Member.lDimID = 1
    inner JOIN <APP>CUSTOMITEM Parent -- Parent Detail
    on Parent.ItemID = dim.ParentID AND Parent.lDimID = 1

    Did you get a chance to look at this guide chapter 7?
    [http://help.sap.com/businessobject/product_guides/boexir31/en/xi3-1_designer_en.pdf]
    Bashir Awan

  • Query to create a view using the following tables

    Hi,
    I am struggling to write the proper query to create a view using three tables.
    I would really be thankful if anyone can help me.
    I am pasting the following script to create the required tables and also insert appropriate data in each of the table.
    create table HR.STUDENT_DETAILS (
    STUDENT_ID NUMBER(10),
    STUDENT_NAME VARCHAR2(50),
    DOB DATE,
    SEX CHAR(1),
    ACTIVE CHAR(1),
    CONTACT_NUMBER NUMBER(20),
    primary key(STUDENT_ID)
    create table HR.PAYMENT_HEADER (
    PAY_HEADER_ID NUMBER(10),
    DOC_NUM NUMBER(5),
    MONTH_NAME VARCHAR2(10),
    primary key(PAY_HEADER_ID)
    create table HR.PAYMENT_DETAILS (
    HEADER_ID NUMBER(10),
    LINE_ID NUMBER(10),
    STUDENT_ID NUMBER(10),
    CUM_AMOUNT NUMBER(10),
    primary key(HEADER_ID,LINE_ID)
    INSERT ALL
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1112,'James','17-JUN-05','M','Y',23674378)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1113,'David','21-SEP-05','M','Y',24565457)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1114,'Michael','13-JAN-06','M','Y',25436784)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1115,'Joseph','03-JAN-06','M','Y',23435673)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1116,'Juliet','21-MAY-05','F','Y',23234527)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1117,'Monica','25-JUN-05','F','Y',24873245)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1118,'William','05-FEB-05','M','Y',23623245)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1119,'Karen','07-FEB-06','F','Y',26757543)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1120,'Erika','17-AUG-05','F','Y',25435465)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1121,'Noah','16-AUG-05','M','Y',23457645)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1122,'Angelina','28-SEP-05','F','Y',26456787)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1123,'Gabriela','30-SEP-05','F','Y',29767543)
    INTO HR.STUDENT_DETAILS (STUDENT_ID,STUDENT_NAME,DOB,SEX,ACTIVE,CONTACT_NUMBER) VALUES (1124,'Sofia','07-MAR-06','F','Y',27656578)
    SELECT * FROM DUAL;
    INSERT ALL
    INTO HR.PAYMENT_HEADER (PAY_HEADER_ID,DOC_NUM,MONTH_NAME) VALUES (305,1,'JAN')
    INTO HR.PAYMENT_HEADER (PAY_HEADER_ID,DOC_NUM,MONTH_NAME) VALUES (306,2,'FEB')
    INTO HR.PAYMENT_HEADER (PAY_HEADER_ID,DOC_NUM,MONTH_NAME) VALUES (307,3,'MAR')
    INTO HR.PAYMENT_HEADER (PAY_HEADER_ID,DOC_NUM,MONTH_NAME) VALUES (308,4,'APR')
    INTO HR.PAYMENT_HEADER (PAY_HEADER_ID,DOC_NUM,MONTH_NAME) VALUES (309,5,'MAY')
    SELECT * FROM DUAL;
    INSERT ALL
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (305,12,1112,40)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (305,13,1113,40)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (305,14,1114,40)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (306,15,1112,80)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (306,16,1113,80)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (306,17,1114,80)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (306,18,1115,40)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (306,19,1116,40)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (307,20,1112,120)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (307,21,1113,120)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (307,22,1114,120)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (307,23,1115,80)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (307,24,1116,80)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (307,25,1117,40)
    INTO HR.PAYMENT_DETAILS (HEADER_ID,LINE_ID,STUDENT_ID,CUM_AMOUNT) VALUES (307,26,1118,40)
    SELECT * FROM DUAL;
    The above table STUDENT_DETAILS stores the details of all the students and each student has a unique student id.
    Another table PAYMENT_HEADER saves the payment details as a document for each month which has a header id.
    In the PAYMENT_DETAILS table, payment details are stored for the students (who made the payment for that month). This table does not save the data for a student if he has not paid on that month. This table is connected to the PAYMENT_HEADER table through a header Id.
    The view should be such that when I pass the document number, it shall show the names of all the students, but shall show payment amount only for those students who had paid under the selected document number, for other it should show null.
    I tried the following query:
    select * from (
    select sd.student_name,sd.DOB,sd.sex,sd.contact_number,pd.doc_num,pd.month_name,pd.cum_amount
    from hr.student_details sd left join
    (select hdr.doc_num,hdr.month_name,det.student_id,det.cum_amount
    from hr.payment_header hdr, hr.payment_details det
    where hdr.pay_header_id = det.header_id) pd on sd.student_id = pd.student_id)
    But when I pass the filtering values like document number, it does not show some students with null values.
    select * from (
    select sd.student_name,sd.DOB,sd.sex,sd.contact_number,pd.doc_num,pd.month_name,pd.cum_amount
    from hr.student_details sd left join
    (select hdr.doc_num,hdr.month_name,det.student_id,det.cum_amount
    from hr.payment_header hdr, hr.payment_details det
    where hdr.pay_header_id = det.header_id) pd on sd.student_id = pd.student_id)
    where doc_num = 1 or doc_num is null;
    My requirement is that, every time I use a document number in the where clause for the view it should show the paid amount against the student names who has paid on that month and for all other student it should null. Total student number is 13. So every time it should show 13 students only even when I pass document No 2 or 3.
    Seeking your help.
    Regards
    Hawker

    Hi Frank,
    as per your advice, I am omitting the 'DOB', 'GENDER','ACTIVE','CONTACT_NUMBER' fields from the 'STUDENT_DETAILS' table.
    I shall create separate tables and insert the desired output from the view for each where clause.
    First let us create three tables each for the desired out put:
    1) For the desired output I want to see when I pass doc_num as 1
    create table HR.SDT_PAY_DET_DOC_ONE (
    STUDENT_ID NUMBER(10),
    STUDENT_NAME VARCHAR2(50),
    DOC_NUM NUMBER(5),
    C_AMOUNT NUMBER(10),
    primary key(STUDENT_ID)
    2) For the desired output I want to see when I pass doc_num as 2
    create table HR.SDT_PAY_DET_DOC_TWO (
    STUDENT_ID NUMBER(10),
    STUDENT_NAME VARCHAR2(50),
    DOC_NUM NUMBER(5),
    C_AMOUNT NUMBER(10),
    primary key(STUDENT_ID)
    3) For the desired output I want to see when I pass doc_num as 3
    create table HR.SDT_PAY_DET_DOC_THREE (
    STUDENT_ID NUMBER(10),
    STUDENT_NAME VARCHAR2(50),
    DOC_NUM NUMBER(5),
    C_AMOUNT NUMBER(10),
    primary key(STUDENT_ID)
    Now I shall insert values in each of the above three tables:
    INSERT ALL
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1112,'James',1,40)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1113,'David',1,40)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1114,'Michael',1,40)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1115,'Joseph',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1116,'Juliet',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1117,'Monica',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1118,'William',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1119,'Karen',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1120,'Erika',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1121,'Noah',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1122,'Angelina',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1123,'Gabriela',null,null)
    INTO HR.SDT_PAY_DET_DOC_ONE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1124,'Sofia',null,null)
    SELECT * FROM DUAL;
    INSERT ALL
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1112,'James',2,80)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1113,'David',2,80)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1114,'Michael',2,80)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1115,'Joseph',2,40)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1116,'Juliet',2,40)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1117,'Monica',null,null)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1118,'William',null,null)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1119,'Karen',null,null)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1120,'Erika',null,null)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1121,'Noah',null,null)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1122,'Angelina',null,null)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1123,'Gabriela',null,null)
    INTO HR.SDT_PAY_DET_DOC_TWO(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1124,'Sofia',null,null)
    SELECT * FROM DUAL;
    INSERT ALL
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1112,'James',3,120)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1113,'David',3,120)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1114,'Michael',3,120)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1115,'Joseph',3,80)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1116,'Juliet',3,80)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1117,'Monica',3,40)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1118,'William',3,40)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1119,'Karen',null,null)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1120,'Erika',null,null)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1121,'Noah',null,null)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1122,'Angelina',null,null)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1123,'Gabriela',null,null)
    INTO HR.SDT_PAY_DET_DOC_THREE(STUDENT_ID,STUDENT_NAME,DOC_NUM,C_AMOUNT) VALUES (1124,'Sofia',null,null)
    SELECT * FROM DUAL;
    Thanks & Regards
    Hawker

  • Memory usage Common table Expressions

    Hope view will use temporary memory while using it.. and
    If I use Common table Expressions (with <datsetname> select query )
    in stored procedure instead of view will it use the temp memory ?
    Many thanks
    Kalinga

    Why would it be any different? Its still a query. It will use any memory available for sorting
    (defined by sort_area_size)
    and if it exceeds this it will use the temporary tablespace.
    If their is more than one temporary tablespace , it will use the temporary tablespace which that user has been assigned.

  • Common table expression

    Hi,
    In DB2, there is a concept called 'common table expressions'.
    A common table expression is like a temporary view that is defined and used for the duration of an SQL statement. You can define a common table expression for the SELECT, INSERT, and CREATE VIEW statements. Each common table expression must have a unique name and be defined only once. However, you can reference a common table expression many times in the same SQL statement.
    Eg :--
    insert into test1 with test_view1(column2) as (select colum1 * 2 from test2) select column2 from test_view1;
    Here 'test_view1' is a temporary view created with a select statement. This view has the scope only within this SQL statement. The data inserted into the table 'test1' is selected from the temporary view.
    This can be achieved in Oracle by creating views and then using the INSERT .. SELECT statement. But I like to know whether any direct equivalent available for this in Oracle, something like 'INSERT .. WITH <view_name>' as in DB2.
    Please advise,
    Thanks,
    Smitha

    Er...you mean like this?
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    JServer Release 9.2.0.6.0 - Production
    SQL> INSERT INTO emp
      2     WITH v_emp AS
      3          (SELECT empno + 1, ename, job, mgr,
      4                  hiredate, sal, comm, deptno
      5           FROM   emp)
      6     SELECT *
      7     FROM   v_emp;
    14 rows created.
    SQL> No, nothing like that whatsoever.

  • [ADF Help] How to create a view for multiple tables

    Hi,
    I am using Jdeveloper 11G and ADF framework, and trying to create a view to update multiple tables.
    ex:
    Table A has these fields: ID, Name
    Table B has these fields: ID, Address
    A.ID and B.ID are primary keys.
    B.ID has FK relationship with A.ID
    (basically, these tables have one-to-one relation)
    I want to create a view object, which contains these fields: B.ID (or A.ID), A.Name, B.Address.
    So I can execute C,R,U,D for both tables.
    I create these tables in DB, and create entity objects for these tables.
    So there are 2 entity objects and 1 association.
    Then I create a view object based on B and add fields of A into the view:
    If the association is not a "Composition Association",
    when I run the model ("Oracle Business Component Browser") and try to insert new data, fields of A can't edit.
    If the association is a "Composition Association", and click the insert button, I will get
    "oracle.jbo.InvalidOwnerException: JBO-25030: Failed to find or invalidate owning entity"
    If I create a view object based on A and add filed of B into the view:
    When I run the model and try to insert new data, fields of B can't edit, no matter the association is or is not a composition association.
    So... how can I create a view for multiple tables correctly?
    Thanks for any advices!
    Here are some pictures about my problem, if there is any unclear point, please let me know.
    http://leonjava.blogspot.com/2009_10_01_archive.html
    (A is Prod, B is CpuSocket)
    Edited by: user8093176 on Oct 25, 2009 12:29 AM

    Hi Branislav,
    Thanks, but the result is same ....
    In the step 2 of creating view object, I can select entity objects to be added in to the view.
    If I select A first, and then select B (the "Source Usage" of B is A), then finishing the wizards.
    When I try to create a new record in the view, I can't edit any properties of B (those files are disabled).
    If I select B first, and then select A in crating view object, the result is similar ...
    Thanks for any further suggestion.
    Leon

  • Problem in  Creating a view using infotypes PA0001,PA0002,...

    Hi,
    Can anybody please help me how to create a Maintainence view using PA0001,PA0002,PA0003,PA0006,PA0032.
    I tried to create it using se54.
    when i use PA0003 as check table, i am not able to create relations with PA0001,PA0002,PA0032,PA0006.
    Thanks in Advance.
    Vinay.BR

    You can create a view using SE11 as mentioned in the previous answer. Once you created, you can use SE16 to display the content of the view table. However, this does not serve much because you can also see the original table using SE16. Unless you want to generate screen dialog so that the view table can be used in SM30. This method can be done while editing the table in SE11. Click on Utilities->Table maintenance generator. However, this will be considered as a repair (modification to SAP standard) and you need repair key.

  • Create a view using a select statement

    Hi
    I need to create a view using a select statement to view details from 2 different tables which will only show data where the holidays commence after june.
    I am new to oracle so any help will do.
    Thanks

    Hi
    I need to create a view using a select statement to view details from 2 different tables which will only show data where the holidays commence after june.
    I am new to oracle so any help will do.
    Thanks

  • Datatypes in a recursive common table expression

    I'm trying to use a (recursive) common table expression to generate a list of dates. The following code is working fine with 11.2
    WITH dates ( nr, dt ) AS (
        SELECT 1, DATE '2005-02-01'
        from dual
        UNION ALL
        SELECT d.nr + 1, DATE '2005-02-01' + 1
        FROM dates d
        WHERE d.nr < 30
    SELECT dt
    FROM dates;But I would like to avoid repeating the start date in the recursive part, and I tried the following:
    WITH dates ( nr, dt ) AS (
        SELECT 1, DATE '2005-02-01'
        from dual
        UNION ALL
        SELECT d.nr + 1, d.dt + 1
        FROM dates d
        WHERE d.nr < 30
    SELECT dt
    FROM dates;But I get the following error: ORA-01790: expression must have same datatype as corresponding expression
    Now from my understanding the datatype should be DATE for both parts of the UNION.
    I also tried it with d.dt + interval '1' day but that produces the same error message. using to_date() instead of the ANSI date literal does not change it either.
    What am I missing here?

    castorp wrote:
    I'm trying to use a (recursive) common table expression to generate a list of dates. The following code is working fine with 11.2
    WITH dates ( nr, dt ) AS (
    SELECT 1, DATE '2005-02-01'
    from dual
    UNION ALL
    SELECT d.nr + 1, DATE '2005-02-01' + 1
    FROM dates d
    WHERE d.nr < 30
    SELECT dt
    FROM dates;But I would like to avoid repeating the start date in the recursive part, and I tried the following:
    WITH dates ( nr, dt ) AS (
    SELECT 1, DATE '2005-02-01'
    from dual
    UNION ALL
    SELECT d.nr + 1, d.dt + 1
    FROM dates d
    WHERE d.nr < 30
    SELECT dt
    FROM dates;But I get the following error: ORA-01790: expression must have same datatype as corresponding expression
    Now from my understanding the datatype should be DATE for both parts of the UNION.
    I also tried it with d.dt + interval '1' day but that produces the same error message. using to_date() instead of the ANSI date literal does not change it either.
    What am I missing here?http://www.orafaq.com/forum/mv/msg/95011/463394/102589/#msg_463394

  • What happens to unused common table expressions ,Does this affect in performance or ?

    If I write a query with one or more common table expressions to which I
    don't actually refer in the query, do they just get pruned off or do
    they get executed regardless? how does it affect in performance
    Prem Shah

    Try below
    seems when the CTE is not refer in the query then statement inside CTE is not executing at all even if it nested CTE, see for your self
    Create table UserInfo
    UserId int primary key,
    UserName varchar(30)
    GO
    Create table UserInfo1
    UserId int primary key,
    UserName varchar(30)
    GO
    insert into UserInfo
    select 1001,'X1' union all
    select 1002,'X2' union all
    select 1009 ,'X9'
    GO
    insert into UserInfo1
    select 1001,'X1' union all
    select 1002,'X2' union all
    select 1009 ,'X9'
    GO
    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
    GO
    Begin tran
    select * from UserInfo1 where UserId between 1001 and 1009
    and UserName = 'XXXX'
    --Commit
    PRINT 'WITH out CTE access in select'
    SET STATISTICS IO ON
    ;WITH CTE1 AS
    (Select * From UserInfo1)
    select * From UserInfo
    PRINT 'WITH CTE access in select'
    ;WITH CTE1 AS
    (Select * From UserInfo1)
    select * From UserInfo a inner join CTE1 b on a.UserId=b.UserId
    Stats IO
        WITH out CTE access in select
        (3 row(s) affected)
        Table 'UserInfo'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
        (1 row(s) affected)
        WITH CTE access in select
        (3 row(s) affected)
        Table 'UserInfo1'. Scan count 0, logical reads 6, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
        Table 'UserInfo'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
        (1 row(s) affected)
    Thanks
    Saravana Kumar C

  • Create Report Painter using LIS table

    Hi Expert,
    I'n new in ECC version but I found we can create report painter using LIS table,
    but I'm not success to create report without error or debug
    Anybody have the documentation about it ?  or tell me how it works ...
    Please ..urgent...need to tell client about it..
    Thanks

    Hi,
    I have not worked on it but you can try this out:
    TCODE for report writer table is GRCT.
    There You need to add your z fields in some pre-defined structure like CCSS and then activate the structure and then activate characteristics.
    NOTE: 24 charcter is max. length for the characteristics.
    Regards,
    Harsh.

  • How to create MRP view using BO BUS1001006 & Method CreateViews.

    Guys,
    I need to create MRP view using BO BUS1001006 & Method CreateViews.
    i am not able to unterstand, what i need to specify to create MRP view, other than material number.
    what field i need to send for MRP view.
    Regards.
    santosh.
    Edited by: santosh koraddi on Jun 23, 2010 6:14 PM

    Hi,
    I have a similar question, have done a search and I see this sort of thing has come up a few times but with no definitive answer.... this thread seems close but don't really understand the solution (I'm not an ABAPER)
    I have a material master creation workflow under construction, it uses BUS1001006 and method createviews.
    The issues is that I want to restrict creation of certain views to certain agents, I have a fork in my workflow and its meant to split up the various views for various agents.
    The problem is that if an agent in one of the forks completes their views the workflow tries to get them to completes teh other views which they do not have authoisation to do... anyway the end result is that the workflow thinks all teh views have been created and the workflow items dissappear from the others inboxes.
    How do I setup my workflow such that each agent in each fork only has to complete the views they have authorisation to maintain and leaves work items in the inboxes of other agents for them to complete?

  • Creating Object views using XSU PL/SQL.Please SEE.

    Hi,
    I am presently using XSU PL/SQL utility with Oracle 9i and using the
    DBMS_XMLQuery.newContext(<My Select clause goes here>,and the
    DBMS_XMLQuery.getXML()which generates an XML document.
    My query is:
    I have 2 tables (One master and the other detail table.).
    Table : DI_Master
    di_num
    00001
    Table: DI_Details
    di_num di_act
    00001 ABCD
    00001 ANCF
    00001 IOPP
    Now the XML I'd like is :
    <di_num>00001</di_num>
    <di_act>
    <val>ABCD</val>
    <val>ANCF</val>
    <val>IOPP</val>
    </di_act>
    Do I need to create object tables for this,insert data into object tables
    and then read this table? It will become an extremely tedious process
    I guess an OBJECT view can do what I want.Can anyone please tell me how
    to write an object view for the 2 tables please and the get the output as
    desired.?

    Supposing you have further
    nesting of the tables.Then how will you go about doing that.You can have multiple levels of CURSOR expressions (see an example below, not a real-life example, but illustrates the point).
    SQL> set long 4000
    SQL> select dbms_xmlquery.getXML('select deptno,' ||
      2  'cursor(select empno, cursor(select losal, hisal from salgrade) salgrades '||
      3   'from emp e where e.deptno = d.deptno and rownum < 3) EMPLOYEES ' ||
      4  'from dept d where d.deptno = 10')
      5  FROM DUAL;
    DBMS_XMLQUERY.GETXML('SELECTDEPTNO,'||'CURSOR(SELECTEMPNO,CURSOR(SELECTLOSAL,HIS
    <?xml version = '1.0'?>
    <ROWSET>
       <ROW num="1">
          <DEPTNO>10</DEPTNO>
          <EMPLOYEES>
             <EMPLOYEES_ROW num="1">
                <EMPNO>7782</EMPNO>
                <SALGRADES>
                   <SALGRADES_ROW num="1">
                      <LOSAL>700</LOSAL>
                      <HISAL>1200</HISAL>
                   </SALGRADES_ROW>
                   <SALGRADES_ROW num="2">
                      <LOSAL>1201</LOSAL>
                      <HISAL>1400</HISAL>
                   </SALGRADES_ROW>
                   <SALGRADES_ROW num="3">
                      <LOSAL>1401</LOSAL>
                      <HISAL>2000</HISAL>
                   </SALGRADES_ROW>
                   <SALGRADES_ROW num="4">
                      <LOSAL>2001</LOSAL>
                      <HISAL>3000</HISAL>
                   </SALGRADES_ROW>
                   <SALGRADES_ROW num="5">
                      <LOSAL>3001</LOSAL>
                      <HISAL>9999</HISAL>
                   </SALGRADES_ROW>
                </SALGRADES>
             </EMPLOYEES_ROW>
             <EMPLOYEES_ROW num="2">
                <EMPNO>7839</EMPNO>
                <SALGRADES>
                   <SALGRADES_ROW num="1">
                      <LOSAL>700</LOSAL>
                      <HISAL>1200</HISAL>
                   </SALGRADES_ROW>
                   <SALGRADES_ROW num="2">
                      <LOSAL>1201</LOSAL>
                      <HISAL>1400</HISAL>
                   </SALGRADES_ROW>
                   <SALGRADES_ROW num="3">
                      <LOSAL>1401</LOSAL>
                      <HISAL>2000</HISAL>
                   </SALGRADES_ROW>
                   <SALGRADES_ROW num="4">
                      <LOSAL>2001</LOSAL>
                      <HISAL>3000</HISAL>
                   </SALGRADES_ROW>
                   <SALGRADES_ROW num="5">
                      <LOSAL>3001</LOSAL>
                      <HISAL>9999</HISAL>
                   </SALGRADES_ROW>
                </SALGRADES>
             </EMPLOYEES_ROW>
          </EMPLOYEES>
       </ROW>
    </ROWSET>
    1 row selected.
    SQL>
    Also,isnt it a better option to create a VIEW of the
    Select clause and pass a view to the select clause? At the end of the day, you could use whatever you feel comfortable with, provided that it produces your expected output and looks clean. We are just giving you the ideas, how you implement it actually in your situation, depends upon a lot of factors, that only you know about.

Maybe you are looking for