Create a view  with combine two  queries

Hi I have two sql queries but just the where condition is just differed But i need a separate coulmn in one view. The data is comming from same table. I need to make two different column like qry 1 fullname, qry2.full name like that
first query
Select
SF.Stu_Last_Name || ', ' || SF.stu_First_Name || ' ' || SF.stu_Middle_Name as Full_Name,
SF.Stu_id ,
SF.stu_cur_schl,
SF.REAS_FOR_ENROLL_CODE,
SF.REAS_FOR_ENROLL_DSC,
SF.SIMS_SCHOOL_YEAR,
SF.SIMS_COL_PERIOD,
SF.SIMS_PERIOD_ID,
substr(TF.DATE_SID, 1, 4) as M_Year,
D.MONTH_DESC as MonthName,
LD.LOC_DISTRICT_SHRT_DESC as DistrictCode,
LD.LOC_DISTRICT_DESC as DistrictName,
LD.LOC_KEY ,
LD.LOC_DESC ,
TF.STU_ID as M_SID,
TD.GRADE,
TD.SUBJECT_ID,
TD.SUBJECT_NAME,
TF.CHAR_BCKT_1 as StudentPerformance ,
TF.CHAR_BCKT_2 as TestStatus,
TF.CHAR_BCKT_3 as StudentPerformanceClean,
TF.INT_BCKT_1 as Score1,
TF.INT_BCKT_2 as Score2,
TF.INT_BCKT_4 as CPI
From
Student_Fact SF,
EPMS_PROD.TEST_SUMMARY_FACT2 TF,
TEST_DIM TD,
LOCATION_DIM LD,
EPMS_PROD.DATE_DIM D
where
SF.SIMS_PERIOD_ID=(select max(SF.SIMS_PERIOD_ID) from Student_Fact SF) and
SF.STU_ID=TF.STU_ID and
SF.SIMS_SCHOOL_YEAR=substr(TF.DATE_SID, 1, 4) and
--TD.TEST_ID in(1,4) and TD.SUB_TEST_ID =100 and
TD.TEST_SID=TF.Test_sid and
LD.LOC_SID=TF.Loc_sid and
D.DATE_SID=TF.DATE_SID and
--TF.Stu_id in('1040822404','1091432903') and
TD.SUBJECT_ID<>0 and
TF.CHAR_BCKT_2<>' '
group by
SF.Stu_Last_Name || ', ' || SF.stu_First_Name || ' ' || SF.stu_Middle_Name,
SF.Stu_id,
SF.stu_cur_schl,
SF.REAS_FOR_ENROLL_CODE,
SF.REAS_FOR_ENROLL_DSC,
SF.SIMS_SCHOOL_YEAR,
SF.SIMS_COL_PERIOD,
SF.SIMS_PERIOD_ID,
substr(TF.DATE_SID, 1, 4),
D.MONTH_DESC,
TF.STU_ID,
TD.GRADE,
TD.SUBJECT_ID,
TD.SUBJECT_NAME,
TF.CHAR_BCKT_1,
TF.CHAR_BCKT_2,
TF.CHAR_BCKT_3,
TF.INT_BCKT_1,
TF.INT_BCKT_2,
TF.INT_BCKT_4,
LD.LOC_DISTRICT_SHRT_DESC,
LD.LOC_DISTRICT_DESC,
LD.LOC_KEY,
LD.LOC_DESC
second query
Select
SF.Stu_Last_Name || ', ' || SF.stu_First_Name || ' ' || SF.stu_Middle_Name as SIMS_Full_Name,
SF.Stu_id ,
SF.stu_cur_schl,
SF.STU_REPORTING_ORG_CODE,
SF.REAS_FOR_ENROLL_CODE,
SF.REAS_FOR_ENROLL_DSC,
SF.SIMS_SCHOOL_YEAR,
SF.SIMS_COL_PERIOD,
SF.SIMS_PERIOD_ID,
substr(TF.DATE_SID, 1, 4) as M_Year,
D.MONTH_DESC as MonthName,
LD.LOC_DISTRICT_SHRT_DESC as DistrictCode,
LD.LOC_DISTRICT_DESC as DistrictName,
LD.LOC_KEY as SchoolCode,
LD.LOC_DESC as SchoolName,
LD.LOC_TYPE_CODE,
LD.LOC_TYPE_DESC,
TF.STU_ID as M_SID,
TD.GRADE,
TD.SUBJECT_ID,
TD.SUBJECT_NAME,
TF.CHAR_BCKT_1 as StudentPerformance ,
TF.CHAR_BCKT_2 as TestStatus,
TF.CHAR_BCKT_3 as StudentPerformanceClean,
TF.INT_BCKT_1 as Score1,
TF.INT_BCKT_2 as Score2,
TF.INT_BCKT_4 as CPI
From
Student_Fact SF,
EPMS_PROD.TEST_SUMMARY_FACT2 TF,
TEST_DIM TD,
LOCATION_DIM LD,
EPMS_PROD.DATE_DIM D
where
--SF.SIMS_PERIOD_ID=(select max(SF.SIMS_PERIOD_ID) from Student_Fact SF) and
SF.STU_ID=TF.STU_ID and
SF.SIMS_SCHOOL_YEAR=substr(TF.DATE_SID, 1, 4) and
--TD.TEST_ID in(1,4) and TD.SUB_TEST_ID =100 and
TD.TEST_SID=TF.Test_sid and
LD.LOC_SID=TF.Loc_sid and
D.DATE_SID=TF.DATE_SID and
--TF.Stu_id in('1040822404','1091432903') and
TD.SUBJECT_ID<>0 and
TF.CHAR_BCKT_2<>' ' and
--LD.LOC_TYPE_CODE in (6, 13)
SF.SIMS_COL_PERIOD in ('Mar', 'EOY') and
SF.REAS_FOR_ENROLL_CODE in ('06', '07')
group by
SF.Stu_Last_Name || ', ' || SF.stu_First_Name || ' ' || SF.stu_Middle_Name,
SF.Stu_id,
SF.stu_cur_schl,
SF.STU_REPORTING_ORG_CODE,
SF.REAS_FOR_ENROLL_CODE,
SF.REAS_FOR_ENROLL_DSC,
SF.SIMS_SCHOOL_YEAR,
SF.SIMS_COL_PERIOD,
SF.SIMS_PERIOD_ID,
substr(TF.DATE_SID, 1, 4),
D.MONTH_DESC,
TF.STU_ID,
TD.GRADE,
TD.SUBJECT_ID,
TD.SUBJECT_NAME,
TF.CHAR_BCKT_1,
TF.CHAR_BCKT_2,
TF.CHAR_BCKT_3,
TF.INT_BCKT_1,
TF.INT_BCKT_2,
TF.INT_BCKT_4,
LD.LOC_DISTRICT_SHRT_DESC,
LD.LOC_DISTRICT_DESC,
LD.LOC_KEY,
LD.LOC_DESC,
LD.LOC_TYPE_CODE,
LD.LOC_TYPE_DESC
Can you please help how do do it.
Thanks
Ram

Yes. it is okay when i use Union and create some dummy column in each of the query and do it. But here other people thinks performance may be a issue. Now they r telling try with function or something.
So thats what i am thinking how to resolve in best way... They strongly suggest using function.
is it possible to do it in function?
Than ks
Ram

Similar Messages

  • Can I create a view based on two tables that have the same column name?

    I have two tables A and B. Each table has 50+ columns.
    I want to create a view that includes all the columns in A and all the columns in B. I created a view with a select statement that says
    Select A.*, B.*
    From A, B
    where A.id = B.id
    It returns an error because in each table I have a column that keeps track if a record has been changed called Modified_By. That's where it chokes up on I figure. I would like to write the view without explicitly writing each column name from A and B as part of the select statement. The actual select statement works fine and only bombs when trying to turn the select statement into a view.

    You will have to type the full column list at least once. You can save a few keystrokes (i.e. alias. on every column) by providing the column names to the CREATE part instead of in the SELECT part. Something like:
    SQL> desc t
    Name                                      Null?    Type
    ID                                                 NUMBER
    NAME                                               VARCHAR2(10)
    SQL> desc t1
    Name                                      Null?    Type
    T_ID                                               NUMBER
    LOC_ID                                             NUMBER
    NAME                                               VARCHAR2(15)
    SQL> CREATE VIEW t_v (id, t_name, t_id, loc_id, t1_name) AS
      2  SELECT t.*, t1.*
      3  FROM t, t1
      4  WHERE t.id = t1.t_id;
    View created.HTH
    John

  • Need Help With Combining Two Variables For A Redirect

    Hello-
    <br />
    <br />In a different part of my site (built with ADDT) I have this script that creates a variable by combining two session variables, and then the new variable is submitted into a mysqul database table using a hidden form field:
    <br />
    <br />
    <form>
    <input type="hidden" name="exerreference" id="exerreference" value="<?php echo $_SESSION['kt_login_user']; ?><?php echo $_SESSION['kt_exer_reference']; ?> <br />" />
    <br />
    <br />There is also this part of the script in the header script:
    <br />
    <br />$ins_exer1-&gt;addColumn("exerreference", "STRING_TYPE", "POST", "exerreference");
    <br />
    <br />What I am trying to do now on another page is combine a session variable "kt_login_user" with a piece of dynamic text "AA" so that I can compare it to the field "exerreference" that was inserted into the database using the above script. If the two variables match, the idea is to have a redirect to another page.
    <br />
    <br />So in a hypothetical example, if the value of the session variable "kt_login_user " is "bestperson," and static text is "AA" then I need to create the variable bestpersonAA (because this is how the variables exist in the exerreference recordset). This variable bestpersonAA then needs to be compared to the recordset value exerreference and if they match, the page redirects to ../previous/portalpre.php. If the two variables do not match, then there is no redirect.
    <br />
    <br />Here is what I have so far:
    <br />
    <br />if (isset($_SESSION['kt_login_user']))
    <br />{
    <br />if ($_SESSION['kt_login_user'.'AA'] = $row_Recordsetexer1['exerreference'])
    <br />{
    <br /> header ("Location: ../previous/portalpre.php");
    <br />}
    <br />}
    <br />
    <br />The script doesn't work yet - it's redirecting regardless of if the two varibles match. Any ideas on the correct syntax to get this working correctly?
    <br />
    <br />Thanks
    <br />Dale</form>

    Hi Dale,
    if ($_SESSION['kt_login_user'.'AA'] = $row_Recordsetexer1['exerreference'])
    for checking whether two variables match, you´ll need the == comparison operator:
    if ($_SESSION['kt_login_user'.'AA'] == $row_Recordsetexer1['exerreference'])
    Cheers,
    Günter Schenk
    Adobe Community Expert, Dreamweaver

  • MVC: Create a view which populates two (or more) joined tables in a single view table

    I am beginner in MVC and I would like to create a view which populates two (or more) joined tables in a single view table as described below.
    I have two tables:
    1 - Bloggers: - bloggerID (int);
                        - bloggerName (string)
    2 - Blogs: - blogID (int);
    bloggerID (int);
                    - blogTitle (string);
                    - blogImage (string)
    A blogger can have one or more blogs while one blog must be related to only one blogger.
    I would like to have a view table on my webpage as the following:
    Blogger Name
    Blog Title
    Blog Image
    Noris Gang
    Virus
    virus.jpg
    Noris Gang
    Desktops
    desktop.jpg
    Gauthier
    Books
    books.png
    John Leon
    NNNMHJhjdhj
    Nmbj.jpg
    I'm using MVC 4 (or at least 3).
    Thanks for your help.

    Hello,
    From your description, it is not very clear that what you mean about the View, if it means the View concept in database as SQL Server, your required view should be as below:
    Create view
    as
    Select Bloggers.bloggerName, Bloggers.blogTitle, Bloggers.blogImage
    From Bloggers join Blogs on Bloggers.bloggerID = Blogs. bloggerID
    If it means the UI view in MVC concept, I suggest you could ask it on the MVC forum:
    http://forums.asp.net/1146.aspx
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can i create a view with jdevlopper 10132

    hi,
    i want to know how to create a view with JDeveloper 10132.
    thanks

    Sorry, but I had to jump in here.
    7rouz - you've certainly violated the 10 commandments for posting here...
    Do you want to:
    1). Create a database view directly in the database
    2). Model a database view using the database modeller
    3). Create an ADF BC View Object
    4). Create some type of visual object (web page, Swing panel)
    5). something else.
    Your question is too ambiguous to yield an answer, unless by luck.
    Regards,
    John

  • How to create a view with parameter?

    who can tell me hwo to create a view with
    parameters just like a cursor?

    Hi,
    This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
    Hope this helps...
    Regards,
    Ganesh R

  • Need help in creating a view with Encryption for hiding the code used by the multiple users

    Hi,
    Can anyone help me out in creating view with encryption data to hide the stored procedure logic with other users.
    I have create a stored procedure with encryted view but while running this manually temporary views are getting created, therefore the problem is if there are 500 entries then 500 temp views will get created.
    Any solution to aviod creating temporary views, please refer my code below
    USE [etl_validation]
    GO
    /****** Object:  StoredProcedure [dbo].[Pr_DBAccess_mod]    Script Date: 05/23/2014 12:53:22 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[Pr_DBAccess_mod](@ETL_CONFIG_ID INT)
    AS
    BEGIN
    DECLARE @openquery NVARCHAR(MAX),
     @DATABASENAME NVARCHAR(100),
     @HIERNAME NVARCHAR(100),
     @TABLENAME NVARCHAR(100),
     @SERVERTYPE NVARCHAR(100),
     @SERVERNAME NVARCHAR(100),
     @USERNAME NVARCHAR(100),
     @PASSWORD NVARCHAR(100),
     @ETL_CONFIG_IDN NVARCHAR(100);
     SET @ETL_CONFIG_IDN=CAST(@ETL_CONFIG_ID AS NVARCHAR);
     SET @TABLENAME='Department';
     SET @SERVERTYPE='SQL';
     SET @SERVERNAME ='192.168.31.176';
     SET @DATABASENAME='AdventureWorks2008R2';
     SET @HIERNAME = 'HumanResources';
     IF @SERVERTYPE='SQL'
     BEGIN
    /*SET @openquery= 'SELECT * INTO ##TestTable
                     FROM OPENROWSET(''SQLNCLI'',''server=192.168.31.176;Trusted_Connection=yes;'','''+@query+''')'
    SET @openquery=  'CREATE VIEW '+@TABLENAME+@ETL_CONFIG_IDN+
                     ' WITH ENCRYPTION AS SELECT * FROM OPENROWSET(''SQLNCLI'',''SERVER='+@SERVERNAME+';TRUSTED_CONNECTION=YES;'',''SELECT * FROM '+@DATABASENAME+'.'+@HIERNAME+'.'+@TABLENAME+''')'
    SELECT @openquery
    END
    EXECUTE sp_executesql @openquery
    END

    Hi aa_rif,
    According to your description and code message, you execute the sp_executesql statement in your stored procedure, it indeed create many views with a tablename and ETL_CONFIG_ID named. If you need not to use these temporary views, you can delete them when
    it contains the tablename in one view name.  
    In addition, if you want to create view with encryption in SQL Server, you can use directly the ENCRYPTION option to encrypt the T-SQL of a view in create view commands, for more information, see:
    http://learnsqlserver.in/4/Create-View-With-Encryption.aspx. if not, you can descript more detail about requriements, so that more forum members can involve into the thread and help you
    out. 
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Creating Materialized View with the Distinct key word

    Hi
    I need help to create Materialized View with the Distinct key word.
    my query is
    select distinct col1, col2 from t1;
    is there any alternate of DISTINCT because I can not refresh the MV as fast on demand if I am using it and Fast on Demand is a must for me.

    hi
    check out this link
    http://download-west.oracle.com/docs/cd/B12037_01/server.101/b10736/basicmv.htm#i1007299
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref183
    hope this helps
    CHeers

  • How to create a view with a column of counts of the occurence of values

    If my table is:
    ID
    1
    2
    3
    3
    5
    5
    5
    I want to create a view with the following result:
    ID   COUNT
    1     1
    2     1
    3     2
    5     3
    How would I accomplish this?

    Sorry, my mistake. I was thinking about counting distinct events.
    I created a table with your example values:
    You should do a projection with a calculated column = 1:
    And then add this calculated column as an aggregated measure on the aggregation node:
    Result:
    Cheers,
    Fernando

  • How to create a view with parameters; read the documentation but nothing!

    Hello!
    I'm new to the Oracle world but together with my coworkers we need to very quickly study Oracle to figure out whether we'll add Oracle to our list of supported databases or not.
    Question: How do I create a view with parameters?
    I've read the documentation but I could not find this! I found the sql syntax to create a view but no parameters whatsoever...
    I have found on the web some very complicated way of doing this, but doesn't Oracle support Views with parameters?
    The goal here is to return a recordset, don't forget, so,please don't speak about stored procedures unless you are going to tell me how to get a recordset out of a stored procedure! ;)
    Thanks for all your help and attention!
    Jorge C.

    You can set up a parameterized view via context as follows:
    1. Set up a procedure to set your context values:
    create or replace procedure p_set_context (p_context IN VARCHAR2,p_param_name IN VARCHAR2,p_value IN VARCHAR2)
    as
    BEGIN
    sys.dbms_session.set_context(p_context,p_param_name,p_value);
    END;
    2. Create your context using the procedure you just created
    create or replace context my_ctx using p_set_context
    3. This is the test table I'll use
    create table my_table(col1 number)
    and populate it:
    begin
    for v_index in 1..10
    loop
    insert into my_table values(v_index);
    end loop;
    end;
    and the view that will be parameterised
    create or replace view v_my_table as select col1 from my_table where col1 between sys_context('my_ctx','start_range') and sys_context('my_ctx','end_range')
    4. Now set the parameters using the procedure above.
    begin
    p_set_context('my_ctx','start_range','1');
    p_set_context('my_ctx','end_range','5');
    end;
    5. Selecting from my_table will give you 1 to 10 (no surprise there :-) )
    selectng from v_my_table will give you 1 to 5
    You can use the context to set formats etc using the same principle. A common gotcha to watch for is trying to set the context directly using DBMS_SESSION.SET_CONTEXT instead of creating a procedure. This belongs to SYS and SYS won't have the privileges to set your context so you get an insufficient privileges result leading to much headscratching and unnecessary grants (at least that's my understanding of it).
    Sorry Jorge, as you're new to Oracle I should also have pointed out for completeness sake, that you can change the parameters at any time through recalling the p_set_context, for example, following on from above, after your "select * from v_my_table" and seeing 1 to 5, you could then do
    begin
    p_set_context('my_ctx','start_range','3');
    end;
    and when you requery 'Select * from v_my_table' you will now see rows 3 to 5.
    Bit of a simplistic example, but you can see how easy it is. :-)
    Message was edited by:
    ian512

  • Create a View with Aggregation Function (COUNT)

    I've been looking up and down for a way to create a view with a few basic fields and some other fields containing aggregation function.
    For instance:
    To display a view that contain all the Contract Agreement and the corresponding count of the PO releases.
    Agreement Nbr, Total PO releases
    I need this view so that I can create a search help with this view.
    I found something about the "CREATE VIEW" statement, but I don't have any idea how to use it.
    Any helps toward this matter is very much appreciated, thanks.

    Hello Aldern
    I guess you have read about the SQL statement "CREATE VIEW". When we create a view in the dictionary this SQL statement is finally called to create the view on the DB. Thus, since we do not have any aggregation options in views you cannot achieve what you want using views.
    The solution for your problem is to create a <b>search help</b> having a <b>search help exit</b>. Within the exit you can do your aggregation functions and add these values to the displayed search help data.
    Regards
      Uwe

  • Create a view with parameter

    it's posible create a view with parameters?
    i want to create a view and pass it parameters, in the same way when i create a procedure or function.
    i never have seen it, but i would like to know if that's posible
    thanks

    You cannot create a view with parameters. The only way is to use a stored proc to dynamically create the sql statement. The substitution variable approach does not work. SQL*Plus will prompt for the value of the variable at compile time (i.e. when you create the view) and use the value you provide in the view's query.
    SQL> create or replace view jws_test_v as
      2  select * from jws_test where flag = '&flg'
      3  /
    Enter value for flg: AA
    old   2: select * from jws_test where flag = '&flg'
    new   2: select * from jws_test where flag = 'AA'
    View created.
    SQL> select * from jws_test_v
      2  /
    no rows selected
    SQL> select text from user_views where view_name = 'JWS_TEST_V'
      2  /
    TEXT
    select "LEV1","LEV2","LEV3","LEV4","LEV5","LEV6","FC","FLAG","ONAFT","ONAPT","CU
    PEFT","CUPEPT" from jws_test where flag = 'AA'This makes sense, since substitution vartiables are a sqlplus construct, not a sql or Oracle construct. A view constructed in this way would not be callable from anywhere other than sqlplus.

  • Creating a view with a primary key

    I want to create a view with a defined primary key. I understand
    the view is created within a select statement, but do not
    understand how you would define a particular field as a primary
    key in the view. Also if your select statement attempts to build
    the view and has duplicate keys in the select result set, what
    would happen when the duplicate key is found? Would it just not
    include the duplicate key in the view?
    Thanks in advance for your help.
    -Pat

    I have a rather difficult problem with duplicate invoice numbers
    contained in unique records. In other words I have many records
    that appear as follows:
    3593, 0004009090, CUSTOMER, TAX, 20000117,014011976-01
    4411, 0004009090, CUSTOMER, TAX, 20000718,014011976-01
    The last field is invoice number '014011976-01' In my case I am
    building a flat file using UTL_FILE for loading into SAP
    Business Warehouse. In SAP I need to have Invoice number as a
    key in which case I can't have duplicate invoice numbers. All
    the SQL I have tried to date returns a large amount of records
    similar to the above records. I am selecting these records from
    4 different schemas which represent 4 different companies. I
    realize the data is the problem and that the vendor of the
    product I am working with should not allow records with
    duplicate invoice numbers, but I have to get the data loaded as
    that is what they want and are paying for. So back to my View. I
    was hoping to create a view and be able to work in the view to
    remove duplicate records prior to writing them to a file. Any
    suggestions are welcomed.
    Thanks
    -Pat

  • How to create table view with reference table

    Hi experts,
    How to create table view with reference table in SE11, plz gve me stp by stp procedure.
    pints grnded for hlp.

    Hi
    Go to Tcode se11 choose view and enter the name and create a popup opens up choose database view option
    enter the description
    On the left hand side choose the table name.
    Click on view fields tab and choose your table fields.Here you can choose which fields you want in your view.
    Save and then activate.
    Hope this helps.
    Regards,
    Harish

  • Create a View with two BEx Queries in BEx

    Hi Experts,
    I have got a scenario where in I have to create a single view on two BEx queries. Can any one give me the necessary steps to create the View?
    Awaiting for your reply,
    Thanks in advance,
    With kind regards,
    Shreeem

    Hi Shreem,
      I think that can be easily done. Check the below thread
    WAD - Integration of multiple queries
    Also see If you can include the two queries in a workbook and maybe later you can try creating a view on it?
    Thanks

Maybe you are looking for

  • Withholing tax

    Hi experts, In my client site the users go to t.code F-43 for direct billing for the vendor. I am following the same process but the TDS tax codes in vendor master (at the time of payment) is attached.and I have to pay the vendor through Automatic Ou

  • Monthly payment for Adobe Forms Central

    Dear all, I need Adobe Forms Central for my master thesis from now till January 2015. According to the Adobe website I have to pay for one year. Since I am a poor student, do you know how I can solve this? Thank you very much in advance.

  • HT201317 Can the family or person that photo stream was shared with add photos ? How?

    Can family / person that photo stream is shared with add photos to album ? How?

  • Distribution  and allocation

    Hi Gurus, Please could you help me clarify the difference between distribution like top-down and Allocation as in cost allocation concepts? Thanks Markus Z.

  • Cannot listen to BBC radio

    I cannot listen to BBC radio - Error message "Flash not installed" I downloaded latest Adobe Flash Player but still no joy Operating System Windows 7 McAfee virus protection