How to Avoid Self Join

Hi
Assume I have following table
Id Code
1 aa
1 bb
1 cc
2 bb
2 cc
The records will be grouped by Id. I want to find out group containing code say 'aa' and 'bb'.
Is it possible to obtain the desired result in a single query without using Self join?
Regards
~Pravin

This is a little clumsy....Anyway try it:
WITH t AS
(SELECT 1 id,'aa' code FROM dual
UNION ALL
SELECT 1,'bb' FROM dual
UNION ALL
SELECT 1,'cc' FROM dual
UNION ALL
SELECT 2,'bb' FROM dual
UNION ALL
SELECT 2,'cc' FROM dual)
SELECT id FROM t
WHERE code IN('aa', 'bb')
GROUP BY id HAVING COUNT(*) = 2;

Similar Messages

  • How to resolve Self Joins in OBIEE

    Hi All
    Could any one help how to resolve the Self Join relations in OBIEE (ex. "SCOTT.EMP" table has "EMPNO" column which is referenced by "MGR" column in the same table.
    Request:
    Need to drill down from the Top manager to his employees and so on
    Another example can be applied for reporting the Organisation Chart

    This is a great article that shows ho to do the Alias:
    Adding an Alias table within the BI physical layer using Oracle BI Administration Tool
    http://www.mandsconsulting.com/adding-an-alias-table-within-oracle-bi-administration-tool
    Thanks
    Subra

  • How to write self join in sql?

    Hi,
    I have table named "table_upload", column "record_type" value "01,03,04....." and start_date,end_date and so on
    And i will have value for  start_date,end_date only for record_type=01,rest of type these two columns will be null.
    now i need to write query with self join, to include above concept. can any one please help me .
    and my query look like follows,

    I just want to re write
    Please provide DDL+DML + expected output!
    and short explanation what is it that we all ask you for:
    DDL = Data Definition Language. In our case that is, CREATE TABLE statements for your tables and other definitions that are needed to understand your tables structure and there for let us to test and reproduce the problem in our server. Without DDL no one
    can execute any query.
    How to get DDL: Right click on the table in Object Explorer and select script table as CREATE. Post these create table scripts here.
    DML = data manipulation language is a family of queries used for manipulating the data it self like: inserting, deleting and updating data. In our case we need some sample data in order to check the query and get result, so we need some indert query for
    sample data.
    If you post a "create table query" for the tables and "insert <table> query" with some sample, then we could help you without Assuming/Guessing. There is a reason that DDL is generally asked for and expected when discussing query problems - it helps
    to identify issues, clarify terminology and prevent incorrect assumptions.  Sample data also provides a common point of reference for the discussion. A script that can be used to illustrate or reproduce the issue you have, will encourage others to help.
    [Personal Site] [Blog] [Facebook]

  • [JPA] How to avoid excessive joins in queries on InheritanceType.JOINED

    Hi,
    Let me use an over-simplified example to illustrate my question:
    Let's assume I have two classes: SuperClass and SubClass. As the name suggests, SubClass extends SuperClass.
    I have mapped them in JPA via:
    @Inheritance(strategy=InheritanceType.JOINED)
    @DiscriminatorColumn(name="CTYPE", discriminatorType=DiscriminatorType.INTEGER)
    @PrimaryKeyJoinColumn(name="ID")And now let's suppose I run the following query:
    Query q = entityManager.createQuery("select o.id from SubClass o");In this case, TopLink Essentials generates SQL with a join between the base table and the detail table. Why? All I need is the ID which is available in the detail table too. The base table doesn't need to be included in the query.
    Is there a way to avoid the unnecessary join? I even tried mapping the ID column in both entities but it didn't help.
    Best regards,
    Bisser

    Thank you for you reply, Doug!
    I don't want to instantiate SubClass. I only wish to get the ID. I don't need validations or fields from the superclass.
    Should I resort to using native SQL for that?
    (By the way, the real query that I use in my program instantiates a completely different entity. I use the SubClass in a subquery. And I don't need the SuperClass to get involved. I have a foreign key that guarantees that the SuperClass's row exists in the database.)
    Best regards,
    Bisser

  • How to avoid cartesion join is there any alternate way

    Hi,
    I have table
    1.sitemaster
    2.Invmaster
    Sitemaster will have some hundrer sites and Invmaster will have thousands of items or product
    I have an Situation for each site i need to show all product so iam linking with cartetion join but its taking more time
    is there any other alternate way to get same result as cartetion join . Please can any one guide me?

    Hi iam saying i need a result like cartesion join only
    Table invmaster
    INVIID
    SKU
    UPC
    DESCRIPTION
    DATEADDED
    MAINGROUP
    AVAILGROUP
    REPORTGROUP
    COMMGROUP
    TAXGROUP
    EXCHANGEGROUP
    ATTRGROUP
    METERGROUP
    MANUFACTURER
    MANPARTNUM
    MODEL
    ACTIVE
    MADEIN
    QTYSERIAL
    SELLPRICE
    COST
    LOWESTSELLPRICE
    REPLACEMENTCOST
    ALLOWDISCOUT
    DAMAGEWAIVER
    ALLOWSUBRENT
    ALLOWCONSIGNED
    SHELFLOCATION
    BINNUMBER
    PACKAGE
    TYPE
    DEPOSITTYPE
    DEPOSITVALUE
    AFFECTSAVAILABILITY
    URL
    UCDESCRIPTION
    PRINTONORDER
    ISMISCITEM
    LENGTH
    WIDTH
    HEIGHT
    WEIGHT
    BOOKDEPRECIATIONIID
    TAXDEPRECIATIONIID );
    Sitemaster
    SITEIID
    SITEID
    SITENAME
    ADDRESSIID
    GMT
    PARENTIID
    PARENTSERVER
    REGION
    DISTRICT
    CLASS
    SITEPRICEGROUP
    PHONE
    FAX
    DAYSINWEEK
    TIMEZONE
    SHIPDATEOFFSET
    PHYSICALCOUNTSTART
    LOCALE
    GEOGRAPHICALREGION
    CATEGORYGROUPIID
    RETURNDATEOFFSET
    MASTERBILLSHARINGTYPE
    MASTERBILLSHARING
    SERVICECHARGETYPE
    SERVICECHARGEVALUE
    SCONDISCOUNTEDAMOUNT
    SERVICECHARGEONSELLITEMS );
    I have created view such that linking othere table with columns index,
    but only in sitemaster i made cartetion join but my result is as expected but its taking more time below is my
    plan please can you suggest is there any alternate way?
    Execution Plan
    Plan hash value: 4005734062
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 2 | 11822 | 24 (9)| 00:00:01 |
    | 1 | VIEW | ALLITEMVIEW | 2 | 11822 | 24 (9)| 00:00:01 |
    | 2 | UNION-ALL | | | | | |
    | 3 | NESTED LOOPS OUTER | | 1 | 164 | 2 (0)| 00:00:01 |
    |* 4 | TABLE ACCESS BY INDEX ROWID | INVMASTER | 1 | 149 | 2 (0)| 00:00:01 |
    |* 5 | INDEX UNIQUE SCAN | IDX_INVMASTERSKU | 1 | | 1 (0)| 00:00:01 |
    | 6 | TABLE ACCESS BY INDEX ROWID | INVSUBCATEGORY | 2 | 30 | 0 (0)| 00:00:01 |
    |* 7 | INDEX UNIQUE SCAN | PK_INVSUBCATEGORYIID | 1 | | 0 (0)| 00:00:01 |
    |* 8 | HASH JOIN OUTER | | 1 | 1886 | 22 (10)| 00:00:01 |
    | 9 | NESTED LOOPS OUTER | | 1 | 1873 | 19 (0)| 00:00:01 |
    | 10 | NESTED LOOPS OUTER | | 1 | 818 | 17 (0)| 00:00:01 |
    | 11 | VIEW | SITEITEMVIEW | 1 | 676 | 17 (0)| 00:00:01 |
    |* 12 | FILTER | | | | | |
    | 13 | NESTED LOOPS | | 11 | 2827 | 17 (0)| 00:00:01 |
    | 14 | NESTED LOOPS OUTER | | 1 | 226 | 2 (0)| 00:00:01 |
    |* 15 | TABLE ACCESS BY INDEX ROWID| INVMASTER | 1 | 214 | 2 (0)| 00:00:01 |
    |* 16 | INDEX UNIQUE SCAN | IDX_INVMASTERSKU | 1 | | 1 (0)| 00:00:01 |
    | 17 | TABLE ACCESS BY INDEX ROWID| INVSUBCATEGORY | 2 | 24 | 0 (0)| 00:00:01 |
    |* 18 | INDEX UNIQUE SCAN | PK_INVSUBCATEGORYIID | 1 | | 0 (0)| 00:00:01 |
    | 19 | TABLE ACCESS FULL | SITEMASTER | 11 | 341 | 15 (0)| 00:00:01 |
    |* 20 | INDEX RANGE SCAN | IDX_COMSITEAUTHORIZEDPRODUCTS | 1 | 13 | 0 (0)| 00:00:01 |
    |* 21 | INDEX UNIQUE SCAN | IDX_COMSITEAUTHORIZEDPRODUCTS | 1 | 26 | 0 (0)| 00:00:01 |
    | 22 | TABLE ACCESS BY INDEX ROWID | IMAGEFILEREFERENCE | 1 | 142 | 0 (0)| 00:00:01 |
    |* 23 | INDEX RANGE SCAN | IDX_IMAGEFRPARENTIID | 1 | | 0 (0)| 00:00:01 |
    | 24 | VIEW PUSHED PREDICATE | INVITEMVIEW | 1 | 1055 | 2 (0)| 00:00:01 |
    | 25 | NESTED LOOPS | | 1 | 45 | 2 (0)| 00:00:01 |
    | 26 | NESTED LOOPS | | 1 | 30 | 1 (0)| 00:00:01 |
    |* 27 | INDEX UNIQUE SCAN | PK_SITEMASTER | 1 | 10 | 0 (0)| 00:00:01 |
    | 28 | TABLE ACCESS BY INDEX ROWID | INVNONSERIAL | 1 | 20 | 1 (0)| 00:00:01 |
    |* 29 | INDEX UNIQUE SCAN | IDX_INVNONSERIALSITEIIDINVIID | 1 | | 0 (0)| 00:00:01 |
    |* 30 | TABLE ACCESS BY INDEX ROWID | INVMASTER | 1 | 15 | 1 (0)| 00:00:01 |
    |* 31 | INDEX UNIQUE SCAN | PK_INVMASTER | 1 | | 0 (0)| 00:00:01 |
    | 32 | VIEW | | 6 | 78 | 2 (50)| 00:00:01 |
    | 33 | HASH UNIQUE | | 6 | 30 | 2 (50)| 00:00:01 |
    | 34 | INDEX FULL SCAN | PK_SUGGESTEDITEMS | 21 | 105 | 1 (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------------------------

  • How to tune self join query in Oracle 11g

    Oracle & SQL new to me,and I'm still in learning phase.
    Could you please help me to tune below oracle query?? This table contains ~95 lac records and it takes 1 hour to retrieve data using this query.
    Your suggestions/comments/help will be appreciated.
    Thanks in advance.
    SELECT A.CNO AS CNO, A.FNO AS FNO, A.CID AS CID, A.IID AS IID
    FROM CAC_LKP A, (SELECT C_DATE, CNO, FNO
    FROM (SELECT MAX(CAC_LKP.C_DATE) AS C_DATE, CAC_LKP.CNO AS CNO, CAC_LKP.FNO AS FNO
    FROM CAC_LKP
    WHERE ACTIVE = 'Y' GROUP BY CNO, FNO)) B
    WHERE A.C_DATE = B.C_DATE
    AND A.CNO = B.CNO
    AND A.FNO = B.FNO
    AND A.ACTIVE = 'Y'
    Primary key is defied over combination of c_date,iid,active.
    Edited by: 1009236 on Jun 1, 2013 12:52 AM

    >
    SELECT  A.CNO AS CNO,
            A.FNO AS FNO,
            A.CID AS CID,
            A.IID AS IID
    FROM    CAC_LKP A,
                            SELECT  C_DATE,
                                    CNO,
                                    FNO
                            FROM
                                SELECT  MAX(CAC_LKP.C_DATE) AS C_DATE,
                                        CAC_LKP.CNO AS CNO,
                                        CAC_LKP.FNO AS FNO
                                FROM CAC_LKP
                                WHERE ACTIVE = 'Y'
                                GROUP BY CNO, FNO
                        ) B
    WHERE   A.C_DATE = B.C_DATE     AND
            A.CNO = B.CNO           AND
            A.FNO = B.FNO           AND
            A.ACTIVE = 'Y';Hi,
    Before even starting to see why there is a performance problem, I think you should consider the fact that there is logical problem in your WHERE clause. According to what you mentioned the primary key is composed of *(c_date, iid, active)* yet iid is absent in both the global query's WHERE clause and also that of the subquery.
    Consequently the (aggregate) rows in the subquery will not be linked based on a correct logic to the external query.
    Regards,
    Dariyoosh

  • How to avoid Cartesian join in sqlquery

    Please ignore this Thread.
    Thanks
    Lax
    Edited by: LAX_ORA on 05-Nov-2012 08:23

    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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Self join with fact table in Obie 10G

    I am a newbie to obiee.I have a development requirement as follows-
    I need to find supervisors designation with the existing star RPD design. explanation is below
                                                        DIM_Designation(Desig_Wid)
                                                      |(Row_wid)
                                                      |
    DIM_EMPLOYEE--------WORKER_FACT------------DIM_Supervisor
    (Row_Wid)-----------------(Employee_Wid)
                                      (Supervisor_Wid)------------(Row_Wid)
    3 dimension is joined to fact to get employee, his supervisor and designation of employee. now i want to get the supervisor's designation? how is it possible? already employee and supervisor dimension is same W_employee_d table joined with fact as alias DIM_EMPLOYEE and DIM_SUPERVISOR. how to do self join with fact to get supervisor's designation. i do not have any supervisor_desig_wid in fact table. any help is deeply appreciated.

    Yes,Duplicate the fact table create a primary key on the newly fact table alias dimension table.So you can ur data modelling as usual.

  • How to achieve parent-child relationship using self join?

    my table structure is as follows
    parent child name
    -1     1     A1
    1     2     A2
    1     3     A3
    how to achieve the hierarchy model using self join. this can be easily achieved using "connect by prior". but how to achieve the same using self join?

    Hi,
    Yes, that's definitely possible. If you only need to display two levels from the hierarchy, a self-join is a good option. Make it an outer join if you need to show everyone on one level, regardless of whether they have a match on the other level or not; for example, if you want the output:
    child_name     child_id     parent_name     parent_id
    A1          1
    A2          2          A1          1
    A3          3          A1          1It's good that you posted some sample data. Now post the results you want from that data, and your query (what you think is the best attempt you've made so far). If you haven't tried anything so far, then look at some other simple self-join to get ideas.

  • How to avoid duplicates in CROSS JOIN Query

    Hi,
    I am using CROSS JOIN to get all the subset of a table col values as shown below:
    PRODUCT (Col Header)
    Bag
    Plate
    Biscuit
    While doing cross join we will get as
    Bag Bag
    Bag Plate
    Bag Biscuit
    Plate Bag
    Plate Plate
    Plate Biscuit ..... like this
    By placing where condition prod1 <> prod2 to avoid Bag Bag and Plate Plate values. So the output will be like below
    Bag Plate
    Bag Biscuit
    Plate Bag
    Plate Biscuit
    Now "Bag Plate" and "Plage Bag" are same combination how to avoid these records. My expected result is
    Bag Biscuit
    Plate Biscuit
    How to derive this ?
    Sridhar

    Hi,
    This is the the solution that I found as fit to the OP question, but
    Visakh16 already posted the same idea (assuming the names are unique) from the start and I don't think that anyone notice it!
    Sridhar.DPM did
    you check Visakh16's response
    (the second response received)?!?
    I will mark his response as an answer. If this is not what you need pls clarify and you can unmark it :-)
    [Personal Site] [Blog] [Facebook]

  • How to perform a self-join in WebI?

    Post Author: willgreenland
    CA Forum: WebIntelligence Reporting
    I want to perform a self-join on a table in WebI, in order to achieve the following result (of course, if there is another way of doing this I'd be glad to hear it):
    I have a table that lists the department in which an employee is located at given dates in the past:
    EMPLID    DEPT    DATE
    123                Sales    2007...
      I want to use this table to track migration between departments, in other words I want to produce the following output table, showing how in 2008, 5 employees moved from Sales to Marketing (etc):DEPT_A    DATE_A    DEPT_B    DATE_B    COUNT(EMPLID) Sales        2007          Mrkting      2008             5...
    In order to do this in SQL, I would do the following:
    SELECT a.DEPT, b.DEPT, count(distinct EMPLID)FROMEMPL_DEPT a, EMPL_DEPT b        // note the self-join hereWHERE( a.EMPLID = b.EMPLID AND a.DATE = '2007' AND b.DATE = '2008' )GROUP BY a.DEPT, b.DEPT;
    Is there a way of doing this in WebI, ideally without resorting to manual SQL editing (I want this to be a report that other users can make sense of without necessarily getting into the SQL)?

    Post Author: amr_foci
    CA Forum: WebIntelligence Reporting
    you cant do something like that in the WebI directly, you have to manager that at the unvinerse level first
    good luck

  • How to avoid Duplicate Records  while joining two tables

    Hi,
    I am trying to join three tables, basically two tables are same one is like history table, so I wrote a query like
    select
    e.id,
    e.seqNo,
    e.name,
    d.resDate,
    d.details
    from employees e,
    ((select * from dept)union(select * from dept_hist)) d
    join on d.id=e.id and e.seqno=d.seqno
    but this returing duplicate records.
    Could anyone please tell me how to avoid duplicate records of this query.

    Actually it is like if the record is processed it will be moved to hist table, so both table will not have same records and I need the record from both the tables so i have done the union of both the tables, so d will have the union of both records.
    But I am getting duplicate records if even I am distinct.

  • How to re-write this self join update using a CTE

    I would like to improve my performance on this update statement and would like to try re-writing using a CTE:
    UPDATE "usr_sessions" "a" SET "is_ended_at_trustable" = 't'
          WHERE (
            EXISTS (
              SELECT 1
              FROM "usr_sessions" "b"
              WHERE "a"."ended_at" = "b"."started_at"
                AND "a"."usr_space_id" = "b"."usr_space_id"
                AND "a"."account_id" = "b"."account_id"
          ) ) AND "a"."is_ended_at_trustable" IS NULL
    Any help is greatly appreciated!  Open to other suggestions as well if there is a better way!

    If I understood your description correctly, here's a way to accomplish the same thing, while dodging the need for the self join.   The update itself won't be any faster, but the overall query leading to the update will likely be faster sans self-join.
      (If my interpretation wasn't exactly what you meant, tweak the "partition by" clause).
    MERGE is generally considered better then UPDATE, but your particular update isn't at risk for the shortcomings of update (still, Merge is newer, cooler, and more trustworthy).
    Setup_Example_Data:
    Declare @Usr_Sessions table (account_id int, usr_space_id int, is_ended_at_Trustable Char(1), started_at varchar(99), ended_at varchar(99))
    Insert @Usr_Sessions
    Select 1, 10, 't', 'A1', 'A1'
    UNION ALL Select 2, 20, 'f', 'B1', 'B2'
    UNION ALL Select 3, 30, NULL, 'C1', 'C1'
    UNION ALL Select 4, 40, NULL, 'D1', 'D2'
    UNION ALL Select 5, 50, NULL, 'E1', 'E2'
    UNION ALL Select 5, 51, NULL, 'E3', 'E3'
    UNION ALL Select 6, 61, NULL, 'F1', 'F2'
    UNION ALL Select 6, 62, 't', 'F3', 'F3'
    UNION ALL Select 6, 62, 'f', 'F4', 'F4'
    Select 'Before', * from @Usr_Sessions
    OP_Query:
    BEGIN TRAN
    UPDATE A SET is_ended_at_trustable = 't' from @usr_Sessions A-- Select * from @Usr_Sessions "a" --
    WHERE (
    EXISTS (
    SELECT 1
    FROM @usr_sessions "b"
    WHERE "a"."ended_at" = "b"."started_at"
    AND "a"."usr_space_id" = "b"."usr_space_id"
    AND "a"."account_id" = "b"."account_id"
    ) ) AND "a"."is_ended_at_trustable" IS NULL
    Select 'After 1', * from @Usr_Sessions
    ROLLBACK TRAN /* Just to reset test data to original form, so second query below runs against original data */
    Dodge_Self_Join:
    With X as
    Select *
    , count(case when started_at = ended_at and is_ended_at_trustable is null then 'x' else null end)
    over(partition by account_id, usr_space_id) as Updatable
    From @Usr_Sessions
    Update X
    set is_ended_at_Trustable = 'T'
    where Updatable > 0 -- EDIT -- fixed error, previously said "updatable = 1"
    Select 'After 2', * from @Usr_Sessions

  • How to avoid the message in the dashboard report

    Hi,
                       I am developing Dashboard reports(graphs) using WAD. Query and WAD are working fine. I need to put a variable for Calendar Month or Year in the graph .I am populating the Variable with default value initially and I am getting the correct result . But if I change the Variable value second time, I am getting a message (type I(information) ) in the same screen which says that 'You cannot change variable ZCALYEAR_WT01 for charact. 0CALYEAR during query navigation' . And below is the detailed information about the error message.
    The Can be changed in query navigation property has been set for variable ZCALYEAR_WT01, characteristic 0CALYEAR. However, the variable is used in the query in such a way, that the system is unable to apply this change-option.
    This can, for example, occur under the following conditions:
    Characteristic 0CALYEAR is filtered by additional restrictions (the restrictions must be joined using an OR-connection)
    A second characteristic, which is restricted by a variable, is compounded to charcteristic 0CALYEAR.
    Variable ZCALYEAR_WT01 is a hierarchy node variable, but the hierarchy has not been determined uniquely.
    A variable can be changed during query navigation only if it is used exclusively in a drilldown-characteristic, and there are no further restrictions to the characteristic other than this variable. There must be no additional characteristics with variables compounded to the characteristic you are working with. For variables for hierarchy nodes, the hierarchy must be determined uniquely and agree with the set display hierarchy.
    Also, if the characteristic value is moved, for example (ZCALYEAR_WT01 - 1), the variable is no longer able to be changed when navigating queries.
    System Response
    The entry ZCALYEAR_WT01 Can be changed during query navigation is not applied.
    Procedure
         I checked the query definition and it is not having any offset or any other restrictions for Calendar Year
    It is used for finding the total quantity by country for the year  .Hence Quantity keyfigure is added in the Keyfigures and Country is in the Rows and Calendar Year is restricted with Variable in the global filter .There are no other fields and no other restrictions .
      I am still trying to figure out why the warning apprears in the DashBoard. Since this Dashboard report will be used by the Power users and this warning message will be annoying to them .Hence I need to find how to avoid this message.
    Kindly do let me if anyone has faced this and solved earlier.
    Thanks for your time.
    Thanks & Regards,
    Raja

    Hi Nick,
      Thanks for your suggestion and it  worked for me   I  added the 'System message' web item and set the visibility to 'Hidden'  .Now I am not getting any message. Thank you for both.
    Thanks & Regards,
    Raja

  • How to avoid Flickaring  When Adding data in Addon User Matrix

    Experts,
    I am  Adding Query Result in User Matrix  one by one. but there is lots of Flicker.
    how to Avoid this Flickering.
    Bomiitems = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                    If Bomtyp = "U" And BomNo = "0" Then
                                        BOMItem = "SELECT Distinct T0.[Code], T1.[ItemName] , ( 1 / Isnull(T2.[Qauntity],0))* Isnull((T0.[Quantity]),0),('" & Quanti & "'/ Isnull(T2.[Qauntity],0))* Isnull((T0.[Quantity]),0) as "
                                        BOMItem = BOMItem + " 'Quanti',T1.[Excisable],'N' as U_Rec , T1.[InvntryUom],T0.[Warehouse] 'Warehouse',T0.[IssueMthd]'IssMthd' FROM ITT1 T0  INNER JOIN OITM T1 "
                                        BOMItem = BOMItem + " ON T0.Code = T1.ItemCode  INNER JOIN OITT T2 ON T0.Father = T2.Code "
                                        BOMItem = BOMItem + " WHERE T0.[Father] ='" & Icode & "'"
                                        Bomiitems.DoQuery(BOMItem)
                                    ElseIf Bomtyp = "U" And BomNo <> "0" Then
                                        'BOMItem = "SELECT T0.[Code], T1.[ItemName] , ((T0.[Quantity]/ T2.[Qauntity])*'" & Quanti & "') as 'Quanti',T1.[Excisable],'N' as U_Rec FROM ITT1 T0  INNER JOIN OITM T1 ON T0.Code = T1.ItemCode  INNER JOIN OITT T2 ON T0.Father = T2.Code WHERE T0.[Father] ='" & Icode & "'"
                                        BOMItem = "SELECT T1.[U_Icode], T1.[U_IName],(1 / Isnull(Cast( T0.[U_Bqty]  as Float) ,0)) * Isnull(Cast(T1.[U_Quanti]  As Float),0) ,('" & Quanti & "' / Isnull(Cast( T0.[U_Bqty]  as Float) ,0)) * Isnull(Cast(T1.[U_Quanti]  As Float),0)  as 'Quanti',T2.[Excisable], T0.[U_Rec],T2.[InvntryUom] ,T1.[U_Whs] 'Warehouse','B' AS 'IssMthd' "
                                        BOMItem = BOMItem + "FROM [dbo].[@OITTA]  T0 inner join  [dbo].[@ITTA1]  "
                                        BOMItem = BOMItem + "T1 on t0.cODE = t1.Code INNER JOIN OITM T2 ON  T1.[U_Icode] = T2.[ItemCode]"
                                        BOMItem = BOMItem + " WHERE T0.[U_Icode] = '" & Icode & "' AND   T0.[U_AltBom] ='" & BomNo & "' AND T0.U_Btyp = 'U'  "
                                        Bomiitems.DoQuery(BOMItem)
                                    ElseIf Bomtyp = "P" Then
                                        BOMItem = "SELECT T1.[U_Icode], T1.[U_IName],(1 / Isnull(Cast( T0.[U_Bqty]  as Float) ,0)) * Isnull(Cast(T1.[U_Quanti]  As Float),0),('" & Quanti & "' / Isnull(Cast( T0.[U_Bqty]  as Float) ,0)) * Isnull(Cast(T1.[U_Quanti]  As Float),0)  as 'Quanti',T2.[Excisable], T0.[U_Rec] ,T2.[InvntryUom],T1.[U_Whs] 'Warehouse','B' AS 'IssMthd' "
                                        BOMItem = BOMItem + "FROM [dbo].[@OITTA]  T0 inner join  [dbo].[@ITTA1]  "
                                        BOMItem = BOMItem + "T1 on t0.cODE = t1.Code INNER JOIN OITM T2 ON  T1.[U_Icode] = T2.[ItemCode]"
                                        BOMItem = BOMItem + " WHERE T0.[U_Icode] = '" & Icode & "' AND   T0.[U_AltBom] ='" & BomNo & "' AND T0.U_Btyp = 'P' "
                                        Bomiitems.DoQuery(BOMItem)
                                    End If
                                        Bomiitems.DoQuery(BOMItem)
                                    If Bomiitems.RecordCount > 0 Then
                                        'RecCount1 = RecSet1.RecordCount
                                        Bomiitems.MoveFirst()
                                        i = 0
                                        'osubForm   .Freeze(True)
                                        oMatrix = oForm.Items.Item("1000001").Specific
                                        oMatrix.FlushToDataSource()
                                        While Not (Bomiitems.EoF)
                                            If i = 0 Then
                                                oMatrix.AddRow()
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("LineId", 0, i + 1)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_ItemCode", 0, Bomiitems.Fields.Item(0).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_ItemName", 0, Bomiitems.Fields.Item(1).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_BaseQty", 0, Bomiitems.Fields.Item(2).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_PlanQty", 0, Bomiitems.Fields.Item(3).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_IssueQty", 0, Bomiitems.Fields.Item(3).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_Whs", 0, Bomiitems.Fields.Item("Warehouse").Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_IsueType", 0, Bomiitems.Fields.Item("IssMthd").Value)
                                                Dim orsWhsDetails As SAPbobsCOM.Recordset
                                                Dim strWhsDetails As String
                                                orsWhsDetails = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                                strWhsDetails = "SELECT T0.[OnHand], T0.[IsCommited], T0.[OnOrder],T1.[OnHand] FROM OITW T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode WHERE T0.[ItemCode] ='" & Bomiitems.Fields.Item(0).Value & "' AND   T0.[WhsCode] ='" & Bomiitems.Fields.Item("Warehouse").Value & "' "
                                                orsWhsDetails.DoQuery(strWhsDetails)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_Whsestk", 0, orsWhsDetails.Fields.Item(0).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_AVILSTK", 0, (orsWhsDetails.Fields.Item(0).Value - Bomiitems.Fields.Item(3).Value))
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_PLANTSTK", 0, orsWhsDetails.Fields.Item(3).Value)
                                                oMatrix.LoadFromDataSource()
                                            Else
                                                oMatrix.FlushToDataSource()
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").InsertRecord(i)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("LineId", i, i + 1)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_ItemCode", i, Bomiitems.Fields.Item(0).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_ItemName", i, Bomiitems.Fields.Item(1).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_BaseQty", i, Bomiitems.Fields.Item(2).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_PlanQty", i, Bomiitems.Fields.Item(3).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_IssueQty", i, Bomiitems.Fields.Item(3).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_Whs", i, Bomiitems.Fields.Item("Warehouse").Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_IsueType", i, Bomiitems.Fields.Item("IssMthd").Value)
                                                Dim orsWhsDetails As SAPbobsCOM.Recordset
                                                Dim strWhsDetails As String
                                                orsWhsDetails = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                                strWhsDetails = "SELECT T0.[OnHand], T0.[IsCommited], T0.[OnOrder],T1.[OnHand] FROM OITW T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode WHERE T0.[ItemCode] ='" & Bomiitems.Fields.Item(0).Value & "' AND   T0.[WhsCode] ='" & Bomiitems.Fields.Item("Warehouse").Value & "' "
                                                orsWhsDetails.DoQuery(strWhsDetails)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_Whsestk", i, orsWhsDetails.Fields.Item(0).Value)
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_AVILSTK", i, (orsWhsDetails.Fields.Item(0).Value - Bomiitems.Fields.Item(3).Value))
                                                oForm.DataSources.DBDataSources.Item("@TPROD1").SetValue("U_PLANTSTK", i, orsWhsDetails.Fields.Item(3).Value)
                                                oMatrix.LoadFromDataSource()
                                            End If
                                            i = i + 1
                                            Bomiitems.MoveNext()
                                            oMatrix.LoadFromDataSource()
                                        End While
                                        oMatrix.LoadFromDataSource()
                                    End If
    Regards,
    Pravin Baji

    follow steps
    1)     Execute query so we can get data set
    2)     Clear matrix and data source (omatrix.clear(), oDBS.Clear())
    3)     Open loop
    4)     Insert record to oDBS using oDBS.InsertRecords(oDBS.Offset)
    5)     Then set value using oDBS.Setvalue(u2026u2026
    6)     Move next record
    7)     Finally close the loop
    8)     Matrix load from record set using oMatrix.LoadfromData()
    it will be work

Maybe you are looking for

  • Export with query option

    Hi all! I need export different tables from my 10.2.0.4 database using expdp. Some of this tables, needs be under different conditions. How can I prepare my parameter file for this export? Table1 --> query: where valid=1 Table2 --> query: where valid

  • Plugin evaluation time period

    Hallo-a! I'm using InCopy CS3 and the CS3 SDK (with Xcode). Is there a built-in mechanism for evaluation periods or similar "try it version" restrictions? Regards, Oliver

  • Grand Totals for GOURL columns

    We are having an issue showing Grand Totals for GOURL enabled columns We have enabled GOURL on the amount columns, To enable hyperlink we had to convert the the number column to character. Enabling the Grand total in the Table View is thorwing error

  • How to change background colour?

    Hi I have an image with a statue and different background colours. I want to change the complete background colour around the statue in one colour for example white. I tried several times but it doesnt work. Do you have a suggestion? Thx Dom

  • Yosemite-App Store repeating downloads

    After upgrading to Yosemite on Mac Pro and MacBook Pro, they both show unusual behavior in the App Store.  After upgrading 'Pages' and 'Numbers', the App Store informs me I need to update them, even though it shows below that I have updated them just