Combine queries dynamically (union?)

Hello Friends
I got very tuff problem, plz help me out.
I want to combine some some query's using "UNION" oprator of SQL Server. Supposed we name it as SET 1.
Again I have to make UNION of output of SET1 with n number of SET 1 like query set.
In short dynamically I have to create differnt UNION OF SOME QUERIES & AGAIN MAKE CHAIN of such queries.
If any one have solution for it . Plz replay immdtly.

Thanx For Rplay
Actually I wan to get empids like id from multiple database. & Id Should not be repeated. I have used UNION option. But Dynamically database can be more or less if use more union query become so big. And StringBuffer Become so big. For execution it take time.
So I got one solution for it. I am fetching id from database & storing it in TreeSet Object.
Its very good idea to store record in TreeSet bcoz no Id get repeated.
I got unquie Id & futher I can process. It took very few minutes. If I use UNION it took too much time.
Thanx For ur response
Dinesh

Similar Messages

  • Combined Queries

    Hi
    I have a query regarding combined queries. I am using BO XI R2 Deski. When i create combined queries, i have observed that BO is processing theses queries in the order from right to left i.e it is executing the last two queries first and then then the next right most and so on...
    For example if i want to calculate (A Union B) minus  (C Intersection D). I am unable to frame this query. When i see the SQL the order is different. Please advise how can i set this preference like first calculate ( A Union B) and ( C Intersection D) and then subtract bothe the result sets.
    Thanks,
    Raveendra

    Hi Raveendra,
    I Tried and able to perform operation Separately like (A union B) and (C Intersection D) and also succeed to put the result side by side but not able to succeed in finding the Minus of the results. Because as you said DESKI perform operations from left to right  for each combined query.
    I performed union and Intersection operations separately by using 2 data providers.
    I used demo universe eFashion  for union and intersection.
    The Steps followed are as follows:
    1. Select eFashion Take objects Year, Store Name, Sales revenue
    2. Click Combine Queries and Take same objects because Union operation requires both queries Must have have same objects.
    3. Union these 2 Queries Run The Report you will get the Union of 2 Queries. (A Union B)
    4.Select New Data Provider (Data New Data Provider)
    5. Select Universe you want  Take objects in Query C, I Took Same objects with different condition like (Year Inlist(2002,2003))
    6. Query D with Condition (Year Equalto(2002)) you will get Results (Query C intersection D). Results that contain only Year Equal to 2002.
    Now you have objects from 2 data providers together, Drag and Drop Objects from 2 data providers and put them at different places on Report now you can compare the results.
    Here we canu2019t Minus the results because when you click Edit Data Provider, DESKI will Prompt you to select the data provider to Edit and hence we can perform edit operation on One data provider one at a time and not together.
    I Hope this is useful.
    Thanksu2026
    Pratik

  • Re : How to retrieve Combined Queries (RE Bean SDK) -XIR2 SP2

    Hello all,
    Hope all is well. I am kinda stuck here ...trying to retrieve Combined Queries from WebI Document. I just have 1 report , 1 DP, 1 combined query(union) with 2 nodes coming off of universe ( __NO__ Custom SQL).
    Could someone give me sample code as how to retrieve this...I was able get DP and then Query container...then kinda got lost.How do I retrieve individual query and then get more information of an individual query like DataSourceObject.
    QueryContainer qCont = dataProv.getCombinedQueries();
    int operator = qCont ();
    // getQueryContainerOperator
    // then how doi I proceed further to retrieve individual query.
    Thanks in advance,
    Sam.

    I don't have any code for retrieving the combined queries, however I have some code for retrieving the SQL from a dataprovider- it might give you an idea of how to get the combined query
    oInfoObject = (IInfoObject) oInfoObjects.get(0);
    // Initialize the Report Engine
    ReportEngines oReportEngines = (ReportEngines) oEnterpriseSession.getService("ReportEngines");
    ReportEngine oReportEngine = (ReportEngine) oReportEngines.getService(ReportEngines.ReportEngineType.WI_REPORT_ENGINE);
    // Openning the document
    DocumentInstance oDocumentInstance = oReportEngine.openDocument(oInfoObject.getID());
    DataProvider oDataProvider = null;
    SQLDataProvider oSQLDataProvider = null;
    SQLContainer oSQLContainer_root = null;
    SQLNode oSQLNode = null;
    SQLSelectStatement oSQLSelectStatement = null;
    String sqlStatement = null;
    out.print("<TABLE BORDER=1>");
    for (int i=0; i<oDocumentInstance.getDataProviders().getCount(); i++) {
         oDataProvider = oDocumentInstance.getDataProviders().getItem(i);
         out.print("<TR><TD COLSPAN=2 BGCOLOR=KHAKI>Data Provider Name: " + oDataProvider.getName() + "</TD></TR>");
         oSQLDataProvider = (SQLDataProvider) oDataProvider;
         oSQLContainer_root = oSQLDataProvider.getSQLContainer();
         if (oSQLContainer_root != null) {
              for (int j=0; j<oSQLContainer_root.getChildCount(); j++) {
                   oSQLNode = (SQLNode) oSQLContainer_root.getChildAt(j);
                   oSQLSelectStatement = (SQLSelectStatement) oSQLNode;
                   sqlStatement = oSQLSelectStatement.getSQL();
                   out.print("<TR><TD>" + (j+1) + "</TD><TD>" + sqlStatement + "</TD></TR>");
    out.print("</TABLE>");
    oDocumentInstance.closeDocument();
    Shawn

  • Prompts for Combine similar request (Union query)

    I have been given 5 tables for creating one report out of each table. I created aliases and
    necessary self joins. I now need a summaryreport that combines these five tables. I tried the
    "combine similar request" and the report functions fine. Now I have to create two prompts, one for
    country and one for job. These are fields available in 4 tables and have the same format alongwith
    the same datatypes. Please help me with this.
    Table 1 Report A
    Table 2 Report B
    Table 3 Report C
    Table 4 Report D
    Table 5 Report E
    Table 1 - Table 4 contains Country and Job field which is of the same format and datatype.
    Table 5 does not have these and its not necessary for us to prompt this.
    This has no star schema setup and I am not in a position to get it done as well. I considered each
    table to be a fact table and created aliases, selfjoins etc. Please help with the procedure to
    create the two dashboard prompts. If I choose USA then the first four amongst the union queries
    should reflect data for the USA. The same applies for Job.

    Hello
    Thanks for the reply.
    My problem here is that I have 5 different tables with country fields in them. They are of the same format and datatype but there is no join between these tables. If I choose one Country field from any particular table, then the combine similar request doesnt seem to take it for other queries where the fields come from a different table.
    eg.
    Table 1 - table 5 have country fields
    I choose to create a prompt based on Country from Table 1. The union query doesnt seem to reflect on filtering values on the queries from other tables. It would filter only the values from table 1.
    Please let me know as to what can be done!

  • Combined Queries in BO 4.0 WebI

    Hi,
    I am creating a combined query in the report query panel.  Query 1 has combined query 1 and combined query 2 with UNION Operator.
    The combined query 1 has one dimension from Table1.Col1. The combined query 2 has one dimension from Table2.Col1.
    When clicking the view script i am expecting the query to be as
    select Table1.Col1
    from Table1
    union
    select Table2.Col1
    from Table2
    But the webi is returning the query like below.
    select Table1.Col1
    from Table1, Table2
    where Table1.Col1 = Table2.Col1
    Union
    select Table2.Col1
    from Table1, Table2
    where Table1.Col1 = Table2.Col1
    Can anyone please suggest why it is joining both the tables? Any settings has to be done in the CMC to avoid this join?
    when creating a union query in the universe with these tables no joins are formed.
    Please help me on this. Thanks in advance.

    This is really very strenge could you please check the parameter value in the file<Parameter
    COMBINED_WITH_SYNCHRO
    it should be yes.
    Also, please check if this the universe spacific problem or happening with all the universe. Did you check with taking other dimention value in the combind query.

  • Combine Queries in one workbook

    Hi guys,
    I am looking for a way to combine multiple queries in one workbook.
    For example: If I set a filter in one query to the month November, the same filter (e.g. November) should apply to all other queries (which are on another worksheet or on the same worksheet).
    How can I do this?
    Many thanks,
    Sabin

    Hi Sabine,
    You have two options:
    1.  the easy one is to use same variables in the refresh screen for all queries in the same workbook; if you do this, then use the "refresh all queries" option, you will get the same restrictions applying to all queries in the workbook simultaneously.
    2.  the more difficult way to do this is to use a lot of Visual Basic.  Using Visual Basic, you can "read" the filter value set on a particular query, then "apply" that filter value to every other query in the workbook.  OR, you can use the "Copy Filter Value" function.  I prefer the latter for a number of reasons.
    From your earlier notes, I assume you want to use option 2.  To help you further, it would be useful to know what version of BW you are using, and how your users typically refresh queries (i.e., with a button in the workbook, or using the Business Explorer toolbar?).
    It would also be helpful to know your level of comfort with VBA in Excel.
    Here are some notes on the "Copy Filter Value" function:
    Function SAPBEXcopyFilterValue(fromCell As Range, Optional atCell As Range) As Integer
    • Return value of zero indicates that no errors were encountered.  Otherwise, function returns number of errors encountered.
    • If atCell is not specified, the active cell is used to determine which characteristic to return information for.  If the active cell is not part of a query definition, then function returns an error state.
    • Characteristics (fromCell and atCell) must have same technical name; for example, cannot copy filters for Ship-to (0SHIP_TO) in Sales cube to Ship-to (YCOCUSSH) in a Shipments cube
    • Queries (copying from and to) must be in same Excel Workbook.
    Sub CopyFilterOnce()
    Dim filterRng1 As Range, filterRng2 As Range
        'in this example, we are copying filters from query on sheet
        'with code name Query1 to query on sheet with code name Query2
        Set filterRng1 = Query1.Range("F10")
        Set filterRng2 = Query2.Range("D13")       
        retVal = Run("SAPBEX.xla!SAPBEXcopyFilterValue", filterRng1, filterRng2
    End Sub
    Hope this helps.
    - Pete

  • Combining queries.

    Hi,
    Is there a code when we can combine the following three queries in one and imprrove performance
    DATA: XAUFPL LIKE AFKO-AUFPL,
          XARBPL LIKE CRHD-ARBPL,
          XARBID LIKE V_QAPO-ARBID.
    SELECT SINGLE AUFPL FROM AFKO INTO XAUFPL WHERE AUFNR = '007200000059'.
    SELECT SINGLE ARBID  FROM V_QAPO INTO XARBID WHERE AUFPL = XAUFPL AND VORNR = '0020'.
    SELECT SINGLE ARBPL FROM CRHD INTO XARBPL WHERE OBJID = XARBID.
    WRITE: / XARBPL.

    you can try this:
    SELECT SINGLE CRHD~ARBPL
    FROM AFKO
    INNER JOIN V_QAPO ON V_QAPOAUFPL = AFKOAUFPL
    INNER JOIN CRHD ON CRHDOBJID = V_QAPOARBID
    INTO XARBPL
    WHERE AFKO~AUFNR = '007200000059'
      AND V_QAPO~VORNR = '0020'.
    WRITE: / XARBPL.
    Hope it will be helpful
    Thanks

  • Combined Queries in Crystal

    I need to create a report that answers multiple questions:
    Step 1: List markets where product is distributed by CompanyA
    Step 2: List top 250 markets based on overall product sales across all companies
    I then wish to create a report which contains a union of markets in Steps 1 and 2.  Is this possible, and if so how?
    All help is appreciated.

    Yes it can be done you need to use a command object in Crystal to create you union
    Select , field1, field2, field3 etc..
    from tablea where company = 'Compnay A'
    Union All
    Select Top 250 field 1, field 2, field 3, from table A
    not sure which database you are using but this could wourk for you with some modifications

  • Join/from/where/ combine queries 3

    hello my query below is not working for my cf application can
    you help?
    thanks
    this is my previous question so i tried to do it my self.
    tcase_req.tcase_req_id is added
    tcase.case_id=tcase_req.case_id :note that this is not part of the
    inner join in the from clause. it does not depend on the rest of
    the inner join.
    the reaon for this is that i need to get
    WHERE tcase_req.case_req_typ_cd = cwc and
    tcase_req.case_req_typ_cd = cwnc
    here is the original question
    Hello ,
    I need help again on the inner join/and conditions in the
    where clause
    I have these 2 tables tcase and tcase_req where there common
    field Is the case_id.
    tcase is the parent table and the tcase_req is the child
    table.
    (1)I wanted to add this to the from clause using the inner
    join table . what do I do and where do I put it
    (2)I then need to put a condition in the where clause to
    replace
    WHERE TCASE.CASE_NBR Like '%HPOZ%'
    AND TCASE.CASE_NBR = 'DIR-2004-4269-HPOZ-CCMP'
    by
    WHERE TCASE.CASE_NBR Like '%CWC%' or TCASE.CASE _NBR Like
    '%CWNC%'
    AND TCASE.CASE_NBR = 'DIR-2004-4269-CWC'
    Or TCASE.CASE_NBR = 'DIR-2004-4269-CWNC'
    is this efficient??
    thanks
    SELECT TLA_PROP.PIN,
    TLA_PROP.ASSR_PRCL_NBR,
    TCASE.CASE_NBR,
    TLA_PROP.STR_NBR,
    TLA_PROP.STR_NBR_RNG_END,
    TLA_PROP.STR_FRAC_NBR,
    Tref_plan_area.plan_area_desc,
    TLA_PROP.STR_FRAC_NBR_RNG_END,
    TLA_PROP.STR_DIR_CD,
    TLA_PROP.STR_NM,
    TLA_PROP.STR_SFX_CD,
    TLA_PROP.STR_SFX_DIR_CD,
    TLA_PROP.STR_UNIT_TYP_CD,
    TLA_PROP.UNIT_NBR,
    TLA_PROP.UNIT_NBR_RNG_END,
    TLA_PROP.ZIP_CD,
    TLA_PROP.ZIP_CD_SFX,
    TLA_PROP.CNCL_DIST_NBR,
    TLA_PROP.PLAN_AREA_NBR,
    TLA_PROP.ZONE_REG_CD,
    TAPLC.PROJ_DESC_TXT,
    TCASE.CASE_ID,
    TCASE.CASE_NBR,
    taplc.aplc_id,
    tcase_req.case_req_typ_cd
    FROM TLA_PROP INNER JOIN tref_plan_area ON
    tla_prop.plan_area_nbr = tref_plan_area.plan_area_NBR INNER JOIN
    TLOC ON TLA_PROP.PROP_ID = TLOC.LOC_ID INNER JOIN TAPLC ON
    TLOC.APLC_ID = TAPLC.APLC_ID INNER JOIN TCASE ON TAPLC.APLC_ID =
    TCASE.APLC_ID
    WHERE TCASE.CASE_NBR Like '%CWC%'and
    tcase.case_id=tcase_req.case_id
    (3)To a tcase_req
    Suffix_id are equal to = cwc and cwnc ( in the tcase_req
    table)(Suffix_id is the field that cintains the suffix cwc and cwnc
    for the tcase_req)
    also,
    this is the original query and it works fine
    SELECT TLA_PROP.PIN,
    TLA_PROP.ASSR_PRCL_NBR,
    TCASE.CASE_NBR,
    TLA_PROP.STR_NBR,
    TLA_PROP.STR_NBR_RNG_END,
    TLA_PROP.STR_FRAC_NBR,
    Tref_plan_area.plan_area_desc,
    TLA_PROP.STR_FRAC_NBR_RNG_END,
    TLA_PROP.STR_DIR_CD,
    TLA_PROP.STR_NM,
    TLA_PROP.STR_SFX_CD,
    TLA_PROP.STR_SFX_DIR_CD,
    TLA_PROP.STR_UNIT_TYP_CD,
    TLA_PROP.UNIT_NBR,
    TLA_PROP.UNIT_NBR_RNG_END,
    TLA_PROP.ZIP_CD,
    TLA_PROP.ZIP_CD_SFX,
    TLA_PROP.CNCL_DIST_NBR,
    TLA_PROP.PLAN_AREA_NBR,
    TLA_PROP.ZONE_REG_CD,
    TAPLC.PROJ_DESC_TXT,
    TCASE.CASE_ID,
    TCASE.CASE_NBR,
    taplc.aplc_id
    FROM TLA_PROP INNER JOIN tref_plan_area ON
    tla_prop.plan_area_nbr = tref_plan_area.plan_area_NBR INNER JOIN
    TLOC ON TLA_PROP.PROP_ID = TLOC.LOC_ID INNER JOIN TAPLC ON
    TLOC.APLC_ID = TAPLC.APLC_ID INNER JOIN TCASE ON TAPLC.APLC_ID =
    TCASE.APLC_ID
    WHERE (TCASE.CASE_NBR Like '%CWC%' or TCASE.CASE_NBR Like
    '%CWNC%')

    For guys like us that are not writing queries everyday you
    might try a query
    builder like the one MS Access has.
    "Coldfusionstudent" <[email protected]>
    wrote in message
    news:[email protected]...
    > hello my query below is not working for my cf
    application can you help?
    > thanks
    >
    >
    > this is my previous question so i tried to do it my
    self.
    >
    >
    > tcase_req.tcase_req_id is added
    tcase.case_id=tcase_req.case_id :note
    > that
    > this is not part of the inner join in the from clause.
    it does not depend
    > on
    > the rest of the inner join.
    >
    > the reaon for this is that i need to get
    > WHERE tcase_req.case_req_typ_cd = cwc and
    tcase_req.case_req_typ_cd =
    > cwnc
    >
    > here is the original question
    >
    > Hello ,
    > I need help again on the inner join/and conditions in
    the where clause
    >
    > I have these 2 tables tcase and tcase_req where there
    common field Is the
    > case_id.
    > tcase is the parent table and the tcase_req is the child
    table.
    >
    > (1)I wanted to add this to the from clause using the
    inner join table .
    > what
    > do I do and where do I put it
    >
    > (2)I then need to put a condition in the where clause to
    replace
    > WHERE TCASE.CASE_NBR Like '%HPOZ%'
    > AND TCASE.CASE_NBR = 'DIR-2004-4269-HPOZ-CCMP'
    > by
    > WHERE TCASE.CASE_NBR Like '%CWC%' or TCASE.CASE _NBR
    Like '%CWNC%'
    > AND TCASE.CASE_NBR = 'DIR-2004-4269-CWC'
    > Or TCASE.CASE_NBR = 'DIR-2004-4269-CWNC'
    >
    > is this efficient??
    >
    >
    >
    > thanks
    > --------------------
    >
    > SELECT TLA_PROP.PIN,
    > TLA_PROP.ASSR_PRCL_NBR,
    > TCASE.CASE_NBR,
    > TLA_PROP.STR_NBR,
    > TLA_PROP.STR_NBR_RNG_END,
    > TLA_PROP.STR_FRAC_NBR,
    > Tref_plan_area.plan_area_desc,
    > TLA_PROP.STR_FRAC_NBR_RNG_END,
    > TLA_PROP.STR_DIR_CD,
    > TLA_PROP.STR_NM,
    > TLA_PROP.STR_SFX_CD,
    > TLA_PROP.STR_SFX_DIR_CD,
    > TLA_PROP.STR_UNIT_TYP_CD,
    > TLA_PROP.UNIT_NBR,
    > TLA_PROP.UNIT_NBR_RNG_END,
    > TLA_PROP.ZIP_CD,
    > TLA_PROP.ZIP_CD_SFX,
    > TLA_PROP.CNCL_DIST_NBR,
    > TLA_PROP.PLAN_AREA_NBR,
    > TLA_PROP.ZONE_REG_CD,
    > TAPLC.PROJ_DESC_TXT,
    > TCASE.CASE_ID,
    > TCASE.CASE_NBR,
    > taplc.aplc_id,
    > tcase_req.case_req_typ_cd
    > FROM TLA_PROP INNER JOIN tref_plan_area ON
    tla_prop.plan_area_nbr =
    > tref_plan_area.plan_area_NBR INNER JOIN TLOC ON
    TLA_PROP.PROP_ID =
    > TLOC.LOC_ID
    > INNER JOIN TAPLC ON TLOC.APLC_ID = TAPLC.APLC_ID INNER
    JOIN TCASE ON
    > TAPLC.APLC_ID = TCASE.APLC_ID
    > WHERE TCASE.CASE_NBR Like '%CWC%'and
    tcase.case_id=tcase_req.case_id
    >
    >
    >
    >
    > (3)To a tcase_req
    > Suffix_id are equal to = cwc and cwnc ( in the tcase_req
    table)(Suffix_id
    > is
    > the field that cintains the suffix cwc and cwnc for the
    tcase_req)
    >
    > also,
    > this is the original query and it works fine
    > SELECT TLA_PROP.PIN,
    > TLA_PROP.ASSR_PRCL_NBR,
    > TCASE.CASE_NBR,
    > TLA_PROP.STR_NBR,
    > TLA_PROP.STR_NBR_RNG_END,
    > TLA_PROP.STR_FRAC_NBR,
    > Tref_plan_area.plan_area_desc,
    > TLA_PROP.STR_FRAC_NBR_RNG_END,
    > TLA_PROP.STR_DIR_CD,
    > TLA_PROP.STR_NM,
    > TLA_PROP.STR_SFX_CD,
    > TLA_PROP.STR_SFX_DIR_CD,
    > TLA_PROP.STR_UNIT_TYP_CD,
    > TLA_PROP.UNIT_NBR,
    > TLA_PROP.UNIT_NBR_RNG_END,
    > TLA_PROP.ZIP_CD,
    > TLA_PROP.ZIP_CD_SFX,
    > TLA_PROP.CNCL_DIST_NBR,
    > TLA_PROP.PLAN_AREA_NBR,
    > TLA_PROP.ZONE_REG_CD,
    > TAPLC.PROJ_DESC_TXT,
    > TCASE.CASE_ID,
    > TCASE.CASE_NBR,
    > taplc.aplc_id
    > FROM TLA_PROP INNER JOIN tref_plan_area ON
    tla_prop.plan_area_nbr =
    > tref_plan_area.plan_area_NBR INNER JOIN TLOC ON
    TLA_PROP.PROP_ID =
    > TLOC.LOC_ID
    > INNER JOIN TAPLC ON TLOC.APLC_ID = TAPLC.APLC_ID INNER
    JOIN TCASE ON
    > TAPLC.APLC_ID = TCASE.APLC_ID
    > WHERE (TCASE.CASE_NBR Like '%CWC%' or TCASE.CASE_NBR
    Like '%CWNC%')
    >

  • Link queries dynamically in a work book

    Hi,
    I have a workbook which has two queries (both of type transaction data), embedded. Both of them have a document number which is unique and could exist in both the queries. I want to link the two queries and in my third sheet in the work book I want to print Key figure values of both the queries if two key characteristics ex: doc number and date are the same. Please let me know if there is any thing to be done in the Bex analyzer side other than a "Vlookup" in excel.
    Thanks

    You can use excel macros to achieve this.

  • Combine queries instead of join

    disregard.
    Edited by: Jay on Jan 20, 2011 8:12 AM

    It is always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can we combine prompt values in Webintelligence Report(Combined Q:Union)

    Hi Every One,
    I had 4 Queries which are combined queries(Union).When i run the report ,displaying prompt values which are there in first Query.Can't we get combined prompt values when i run the report.I will explain with Scenario.
    Eg:
    Q1:Product level Country Information
    Prompt Values:Country(A,B,C,D,E,F,G,H)
    Q2:Component level Country Information
    Prompt Values:Country(A,B,C,D,E,F,L)
    Q3:Product level Source Information
    Prompt Values:Country(A,B,C,D,E)
    Q4:Product level Country Information
    Prompt Values:Country(A,B,C,D,E,F,M)
    When i run the report iam getting prompt values for country as (A,B,C,D,E,F,G,H)
    Could you help .
    Regards,
    Swapna.

    I'm having trouble understanding your scenario as you explain it.
    You are doing a union of the queries?
    So create query A, combine queries, union, create query B, etc.
    All of them use the same prompt message?
    So you either build the condition and reuse the same prompt message or you use a filter from the universe.
    In this case it is not possible to specify something different for each of the various subqueries.
    So you would have only one prompt answer, being whatever you answered to the prompt.
    If you have different prompt messages, you can give different answers, but then you have 4 prompt answers to display.
    It would be logical that only the first one is displayed if that is the one you display, you should display all four.
    If you just want to display the superset of countries which have been retrieved by the query you can put this information in a separate table block. If you make it a horizontal one, without borders, you should be able to come close to a normal prompt layout.
    Good luck,
    Marianne

  • Help with using dynamic sql logic in a view please?

    Greetings,
    I want to create a dynamic union using all the databases on server. The following works:
    declare @sqlvarchar(max)
    select
    @sql=IsNull(@sql+'union
    all ','')+'select
    * from  '+name+'.[dbo].[A]''
    inner join '+name+'.[dbo].[B]'' on
    a.f1=b.f1'
    from
    sys.databases
    where
    name
    in(select
    name
    from
    sys.databases)
    exec
    (@sql)
    The problem is I need something tangible, like a view, to query using SSAS later. I've tried to use SELECT into to load a new table with a resulting dataset. It gives me a syntax error - the dynamic part can't be combined with static. I can't use OPENQUERY
    because it all happens on the same server. Assistance would be appreciated. Thanks

    Well, you could regenerate the view each time a database is created or dropped.
    Or you can define your cube using an empty view and load the cube using SSIS, eg with
    Dimension Processing Destination.
    Or you can use something like a CLR TVF inside your view.
    David
    David http://blogs.msdn.com/b/dbrowne/

  • SQL query error using Union

    Hello!
    I need some correction in the following query. I am trying to make a 2 page QPLD so I am joining 2 queries and then printing the report into 2 pages.
    SELECT T0.[U_OANumber], T0.[custmrName], T0.[U_Inspection], T0.[U_Cust_PO_Num],
    T0.[U_ModelType], T0.[U_Duty], T0.[U_NamePlate],
    T0.[U_Indicator_Obs], T0.[U_Fastners], T0.[U_Mounting_Type], T0.[U_Casing_Orientation], T0.[U_Impeller_Dia],
    T0.[U_Bearing_Style], T0.[U_Motor_HP_Size], T0.[U_InsulationWedges], T0.[U_Varnish], T0.[U_Paint_Shade],
    T0.[U_PlugsSeal], T0.[U_Remarks], T0.[U_Despatch]
    FROM OINS T0 WHERE T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
    Union all
    SELECT T0.[U_ModelType], T0.[U_Size], T0.[U_Discharge], T0.[U_Head], T0.[U_RPM], T0.[U_YOM], T0.[U_HP],
    T0.[U_Amps], T0.[U_Insulation_Class], T0.[U_Winding_Connection]
    FROM OINS T0 WHERE
    T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
    Do I have to use the where clause just once since it is identical to both statements?
    I get the error stating that all queries using Union, Intersect or Except must have an equal number of expressions. what does this mean?
    scorp
    Edited by: scorpion 666 on Feb 12, 2009 1:30 PM

    Union has to have exact same numbers of fields to combine two results.  Your query shows no need of union because your where clauses are identical.
    Right syntax would be like this:
    SELECT T0.[U_OANumber], T0.[custmrName], T0.[U_Inspection], T0.[U_Cust_PO_Num],
    T0.[U_ModelType], T0.[U_Duty], T0.[U_NamePlate],
    T0.[U_Indicator_Obs], T0.[U_Fastners], T0.[U_Mounting_Type], T0.[U_Casing_Orientation], T0.[U_Impeller_Dia],
    T0.[U_Bearing_Style], T0.[U_Motor_HP_Size], T0.[U_InsulationWedges], T0.[U_Varnish], T0.[U_Paint_Shade],
    T0.[U_PlugsSeal], T0.[U_Remarks], T0.[U_Despatch], T0.[U_Size], T0.[U_Discharge], T0.[U_Head], T0.[U_RPM], T0.[U_YOM], T0.[U_HP],
    T0.[U_Amps], T0.[U_Insulation_Class], T0.[U_Winding_Connection]
    FROM DBO.OINS T0 WHERE T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
    Thanks,
    Gordon

  • TOPN filter on two combined cubes

    Hi guys,
    do you know how to apply a TOPN filter on two combined queries like the one below:
    SELECT saw_0, saw_1, saw_2 FROM ((SELECT Companies.Company saw_0, "Non Revenue Facts".Rooms saw_1, "Local Revenue Facts"."Room Revenue" saw_2 FROM COMPANY) UNION (SELECT "Travel Agent".Travel saw_0, "Non Revenue Facts".Rooms saw_1, "Local Revenue Facts"."Room Revenue" saw_2 FROM TRAVEL_AGENT)) t1 ORDER BY saw_1 DESC
    The filter should be this one WHERE TOPN("Non Revenue Facts".Rooms,10) <= 10)
    I tried to apply it on each query, but doesn't give the expected results.
    the filter should apply for both queries.
    Any idea?
    Thanks!

    Hello User,
    When you are trying to implement on one query the TOPN function,Are u getting any error? Or just it is not showing the results?
    Do let me know the updates?
    Thanks.

Maybe you are looking for

  • My iphone locked up during an os software update

    During a software update, my iphone has locked up.  the progress bar appears to be about 80% finished (it also shows the apple above it) but it won't go the rest of the way across the screen (from left to right). It's been this way for an hour now. 

  • Program taking up all of CPU Speed

    Hello, I have been lucky not to have to use the forum, until now. I recently installed a program called Garage Sale. I decided not to use it and deleted it (drug it over to trash from the finder window). Well,(now at least a week later) I turned on m

  • Keep alive a session between 2 BAPI calls

    Hi - I am calling several BAPIs to maintain data. I am calling from an outside system as I published the BAPIs as Web Services. I would like that the session between 2 BAPI calls is kept, so I don't miss some session info between call #1 and call #2.

  • Deleting

    How do you delete a complete project? I can't find ANYTHING in the manual on how to do that. Thanks, tom

  • Urgent, rwrun.sh problem

    Dear all, I am having problem to run rwrun.sh from my AIX machine. The version is 5L, with HACMP clustering we are using oracle 9ias When I called rwrun.sh , I hit this java exception : java.lang.String errorString="Caught exception: org.omg.CORBA.OB