Joining Three Tables with multiple record

Dear All
we need some help. We have Three Tables in sqlserver2012
Master Table
OrderID       PackageID      CustomerName
1                          1               Abc
2                          2                Bcd
3                          1                xyz
Child1 Table
OrderID          ControlName
1                   Row1COlumn1             (It Means Pant in Red Color is selected by user(relation with Child2 Table))
1                   Row3Column1             (It Means Gown in Blue Color is selected by user(relation with Child2 Table))
1                   Row4Column3             (It Means T Shirt in White Color is selected by user(relation with Child2 Table))
2                    Row1Column2            (It Means Tie in Green Color is selected by user(relation with Child2 Table))
2                   Row3Column1            (It Means Bow in Red Color is selected by user(relation with Child2 Table))
Child2 Table
PackageID      Product      Color1     Color2    Color3
1                       Pant        Red          Green     Blue    
1                       Shirt        Blue      Pink    Purple
1                       Gown         Blue      Black    Yellow
1                       T Shirt     Red          Green     White
2                       Tie         Red          Green     White
2                       Socks       Red          Green     White
2                       Bow         Red          Green     White
We want to have result like
OrderID    PackageID      CustomerName   Pant    Gown  T Shirt     Tie         Bow  
1                     1                 ABC               Red     Blue    White      x    
      x
                                                               Blue
2                      2                 Bcd                 x         x          x
       Green      Red
I have tried 
;with mycte as (
select  ms.OrderID,ms.PackageID
,ms.CustomerName
, Replace(stuff([ControlName], charindex('Column',ControlName),len(ControlName),''),'Row','')  rowNum 
,Replace(stuff([ControlName], 1, charindex('Column',ControlName)-1 ,''),'Column','') columnNum 
From  child1 c inner join MasterTable ms on c.Orderid=ms.orderid)
,mycte1 as (
select *, row_number() Over(Partition By PackageID Order By Child2ID) rn from child2
,mycte2 as (
Select m.OrderID,m.PackageID, m.CustomerName, m.ColumnNum,  m1.Product 
--,m1.Color1 , m1.Color2, m1.Color3 
, Case WHEN ColumnNum= 1 Then Color1 
 WHEN ColumnNum= 1 Then Color1 
  WHEN ColumnNum= 2 Then Color2 
   WHEN ColumnNum= 3 Then Color3 End Colors  
from mycte m 
join mycte1 m1 on m.rowNum=m1.rn and m.PackageID=m1.PackageID)
Select OrderID,PackageID,CustomerName, ISNULL(Max(Case WHen Product='Pant' Then Colors END),'X') as 'Pant'
, ISNULL(Max(Case WHen Product='Gown' Then Colors END),'X') as 'Gown'
, ISNULL(Max(Case WHen Product='T Shirt' Then Colors END),'X') as 'T Shirt'
, ISNULL(Max(Case WHen Product='Tie' Then Colors END),'X') as 'Tie'
, ISNULL(Max(Case WHen Product='Bow' Then Colors END),'X') as 'Bow'
FROM mycte2
 Group by OrderID,PackageID, CustomerName
it works if we have a product in one color only. like if we have pant in red and blue then its showing just first record
Thanks and Best Regards Umair

Are you really storing textual values like "Row3Column1" or "Row4Column3"???
Your model is a mess. Redesign it.. btw, these kind of models are quite complex.
USE tempdb;
GO
CREATE TABLE dbo.Colors
ColorID INT NOT NULL ,
ColorName NVARCHAR(255) NOT NULL ,
CONSTRAINT PK_Colors PRIMARY KEY ( ColorID )
CREATE TABLE dbo.Products
ProductID INT NOT NULL ,
ProductName NVARCHAR(255) NOT NULL ,
CONSTRAINT PK_Products PRIMARY KEY ( ProductID ) ,
CONSTRAINT UQ_Products_ProductName UNIQUE ( ProductName )
CREATE TABLE dbo.Packages
PackageID INT NOT NULL ,
CONSTRAINT PK_Packages PRIMARY KEY ( PackageID )
CREATE TABLE dbo.PackageDetails
ColorID INT NOT NULL ,
PackageID INT NOT NULL ,
ProductID INT NOT NULL ,
CONSTRAINT PK_PackageDetails PRIMARY KEY ( ColorID, PackageID, ProductID ) ,
CONSTRAINT FK_PackageDetails_ColorID FOREIGN KEY ( ColorID ) REFERENCES dbo.Colors ( ColorID ) ,
CONSTRAINT FK_PackageDetails_PackageID FOREIGN KEY ( PackageID ) REFERENCES dbo.Packages ( PackageID ) ,
CONSTRAINT FK_PackageDetails_ProductID FOREIGN KEY ( ProductID ) REFERENCES dbo.Products ( ProductID )
CREATE TABLE dbo.Orders
OrderID INT NOT NULL ,
CustomerID INT NOT NULL ,
PackageID INT NOT NULL ,
CONSTRAINT PK_Orders PRIMARY KEY ( OrderID ) ,
CONSTRAINT UQ_Orders_CustomerID UNIQUE ( OrderID, PackageID ) ,
CONSTRAINT FK_Orders_PackageID FOREIGN KEY ( PackageID ) REFERENCES dbo.Packages ( PackageID )
CREATE TABLE dbo.OrderDetails
ColorID INT NOT NULL ,
OrderID INT NOT NULL ,
PackageID INT NOT NULL ,
ProductID INT NOT NULL ,
CONSTRAINT FK_OrderDetails_Orders FOREIGN KEY ( OrderID, PackageID ) REFERENCES dbo.Orders ( OrderID, PackageID ) ,
CONSTRAINT FK_OrderDetails_PackageDetails FOREIGN KEY ( ColorID, PackageID, ProductID ) REFERENCES dbo.PackageDetails ( ColorID, PackageID, ProductID )
GO
INSERT INTO dbo.Colors
( ColorID, ColorName )
VALUES ( 1, 'Red' ),
( 2, 'Green' ),
( 3, 'Blue' ),
( 4, 'Pink' ),
( 5, 'Purple' ),
( 6, 'Black' ),
( 7, 'Yellow' ),
( 8, 'White' );
INSERT INTO dbo.Products
( ProductID, ProductName )
VALUES ( 1, 'Pant' ) ,
( 2, 'Shirt' ) ,
( 3, 'Gown' ) ,
( 4, 'T Shirt' ) ,
( 5, 'Tie' ) ,
( 6, 'Socks' ) ,
( 7, 'Bow' );
INSERT INTO dbo.Packages
( PackageID )
VALUES ( 1 ),
( 2 );
INSERT INTO dbo.PackageDetails
( PackageID, ProductID, ColorID )
VALUES ( 1, 1, 1 ),
( 1, 2, 3 ),
( 1, 3, 3 ),
( 1, 4, 1 ),
( 2, 5, 1 ),
( 2, 6, 1 ),
( 2, 7, 1 ),
( 1, 1, 2 ),
( 1, 2, 4 ),
( 1, 3, 6 ),
( 1, 4, 2 ),
( 2, 5, 2 ),
( 2, 6, 2 ),
( 2, 7, 2 ),
( 1, 1, 3 ),
( 1, 2, 5 ),
( 1, 3, 7 ),
( 1, 4, 8 ),
( 2, 5, 8 ),
( 2, 6, 8 ),
( 2, 7, 8 );
INSERT INTO dbo.Orders
( OrderID, PackageID, CustomerID )
VALUES ( 1, 1, 1 ),
( 2, 2, 2 ),
( 3, 1, 3 );
INSERT INTO dbo.OrderDetails
( ColorID, OrderID, PackageID, ProductID )
VALUES ( 1, 1, 1, 1 ),
( 3, 1, 1, 3 ),
( 8, 1, 1, 4 ),
( 2, 2, 2, 5 ),
( 1, 2, 2, 7 );
GO
SELECT *
FROM dbo.Orders O
INNER JOIN dbo.OrderDetails OD ON OD.OrderID = O.OrderID
INNER JOIN dbo.Products P ON P.ProductID = OD.ProductID
INNER JOIN dbo.Colors C ON C.ColorID = OD.ColorID;
GO
DROP TABLE dbo.OrderDetails;
DROP TABLE dbo.Orders;
DROP TABLE dbo.PackageDetails;
DROP TABLE dbo.Packages;
DROP TABLE dbo.Products;
DROP TABLE dbo.Colors;
GO

Similar Messages

  • Select max date from a table with multiple records

    I need help writing an SQL to select max date from a table with multiple records.
    Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
    SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
    0000651005 BASE 15-AUG-07 YES
    0000651005 BASE 13-NOV-09 NO
    0010973671 BASE 20-MAR-08 YES
    0010973671 BASE 18-JUN-10 NO

    Hi,
    Welcome to the forum!
    Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
    For example:
    CREATE TABLE     table_x
    (     sa_id          NUMBER (10)
    ,     char_type     VARCHAR2 (10)
    ,     effdt          DATE
    ,     char_val     VARCHAR2 (10)
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
    COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
    `    SA_ID LAST_EFFD
        651005 13-NOV-09
      10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
    Here's how to get those results:
    SELECT    sa_id
    ,         MAX (effdt)    AS last_effdt
    FROM      table_x
    GROUP BY  sa_id
    ;

  • Populating a temp table with multiple records.

    I want to populate a temp table with a a set of recs. This table will be used for
    crossing/joining with my other tables to pull out data.
    ie:
    Main table (loc)contains these fields -> county,permit,utme,utmn
    Temp table ( tmpid) contains these fields -> countytemp, permittemp
    So I will be doing a statement like this once my temp table is populated.
    Select l.county,l.permit,l.utme,l.utmn from loc l,tmpid t where l.county=t.countytemp and l.permit=t.permittemp;
    So this temp table will basically be a list of ids that can range from a few recs to several hundred.
    I want to know is there is way I can poplulate/repopulate it easily using sqlPlus/other by reading in a Ascii file
    from client PCs. (besides SQL loader).

    HI
    let me explain my requirement first,
    i need to populate my block with the results from the following sql
    SELECT * from contactdet where
    (Month=12 and TrType='MTM' and FinYr='04-05' and Userid='SA009' and Clcode='SB001')
    UNION
    SELECT * from contactdetSUM where (Clcode='SB001' AND CSCODE='AB001')
    Pease note. the where clauses i have put are different in each table and my requirement is
    the constants values i have put in where clause should be variable (ie. i should be able to put variables like :clcode or so)
    I tried us using Query data source type as 'FROM clause query' but it does not allow me to put variables in where clause.
    Is there any way out i can do this ? Please help me
    Regards
    Uday

  • Reg - Reading internal table with multiple record in a single field

    Dear Guru's,
                        i want to read a internal table with field having mutilple entries like
    read table READ TABLE LT_T2 INTO LT_T2_WA WITH KEY HKONT IN ( '0001152430', '0001152930', '0001152410' ).
    But it says comma without preceding colon (after READ?).
    please guide me.....
    thanks & Regards,
    Balaji.S

    ya this is inside the loop.
    plz check....
    loop at lt_t2 into lt_t2_wa.
    READ TABLE LT_T2 INTO LT_T2_WA WITH KEY HKONT IN ( '0001152430', '0001152930', '0001152410' ).
    endloop.
    thanks & Regards,
    Balaji.S

  • Fill a table with multiple records

    REPORT  REPORT1.
    DATA: wa_itab1  LIKE TABLE1.
    DATA: wa_itab2  LIKE TABLE2.
    DATA: itab1 TYPE STANDARD TABLE OF TABLE1,
          itab2 TYPE STANDARD TABLE OF TABLE2.
    DATA: v_dat TYPE d VALUE '20080101'.
    SELECT * FROM TABLE1 INTO TABLE itab1.
    LOOP AT itab1 INTO wa_itab1.
      wa_itab2-FIELD1 = wa_itab1-FIELD1.
      wa_itab2-FIELD2 = wa_itab1-FIELD2.
      wa_itab2-FIELD3 = wa_itab1-FIELD3.
      wa_itab2-FIELD4 = v_dat. "pass the initialized date
      APPEND wa_itab2 TO itab2.
      v_dat = v_dat + 1. " increment the date
      IF v_dat GT '20080105'.
        EXIT.
      ENDIF.
    ENDLOOP.
    MODIFY TABLE2 FROM TABLE itab2.
    I have the program above which is not doing exactly what I need.  Lets say TABLE1 has 3 records
    FIELD1 FIELD2     FIELD3
    PLANT1 STOR_LOC1  20
    PLANT2 STOR_LOC2  30
    PLANT3 STOR_LOC3  40
    The loop is for 5 days so in TABLE2 I want to see the following
    FIELD1 FIELD2     FIELD3  FIELD4
    PLANT1 STOR_LOC1  20     20080101
    PLANT2 STOR_LOC2  30     20080101
    PLANT3 STOR_LOC3  40     20080101
    PLANT1 STOR_LOC1  20     20080102
    PLANT2 STOR_LOC2  30     20080102
    PLANT3 STOR_LOC3  40     20080102
    PLANT1 STOR_LOC1  20     20080103
    PLANT2 STOR_LOC2  30     20080103
    PLANT3 STOR_LOC3  40     20080103
    PLANT1 STOR_LOC1  20     20080104
    PLANT2 STOR_LOC2  30     20080104
    PLANT3 STOR_LOC3  40     20080104
    PLANT1 STOR_LOC1  20     20080105
    PLANT2 STOR_LOC2  30     20080105
    PLANT3 STOR_LOC3  40     20080105
    At the moment the program gives me
    FIELD1 FIELD2     FIELD3  FIELD4
    PLANT1 STOR_LOC1  20     20080101
    PLANT2 STOR_LOC2  30     20080101
    PLANT3 STOR_LOC3  40     20080101
    Do I need a WHERE clause and if so how do I add assuming that the equal fields are FIELD1 and FIELD2? Thanks

    I have added a DO condition to the program and tried a couple of attempts.  The latest is below.  With this attempt I get 80,000+ records the majority of which do not have the fields filled.  Thanks
    REPORT REPORT1.
    DATA: wa_itab1 LIKE TABLE1.
    DATA: wa_itab2 LIKE TABLE2.
    DATA: itab1 TYPE STANDARD TABLE OF TABLE1,
    itab2 TYPE STANDARD TABLE OF TABLE2.
    DATA: v_dat TYPE d VALUE '20080101'.
    SELECT * FROM TABLE1 INTO TABLE itab1.
    DO v_dat+1 TIMES.
    LOOP AT itab1 INTO wa_itab1.
    wa_itab2-FIELD1 = wa_itab1-FIELD1.
    wa_itab2-FIELD2 = wa_itab1-FIELD2.
    wa_itab2-FIELD3 = wa_itab1-FIELD3.
    wa_itab2-FIELD4 = v_dat. "pass the initialized date
    APPEND wa_itab2 TO itab2.
    v_dat = v_dat + 1. " increment the date
    IF v_dat GT '20080105'.
    EXIT.
    ENDIF.
    ENDLOOP.
    ENDDO.
    MODIFY TABLE2 FROM TABLE itab2.

  • How can I convert string to the record store with multiple records in it?

    Hi Everyone,
    How can I convert the string to the record store, with multiple records? I mean I have a string like as below:
    "SecA: [Y,Y,Y,N][good,good,bad,bad] SecB: [Y,Y,N][good,good,cant say] SecC: [Y,N][true,false]"
    now I want to create a record store with three records in it for each i.e. SecA, SecB, SecC. So that I can retrieve them easily using enumerateRecord.
    Please guide me and give me some links or suggestions to achieve the above thing.
    Best Regards

    Hi,
    I'd not use multiple records for this case. Managing more records needs more and redundant effort.
    Just use single record. Create ByteArrayOutputStream->DataOutputStream and put multiple strings via writeUTF() (plus any other data like number of records at the beginning...), then save the byte array to the record...
    It's easier, it's faster (runtime), it's better manageable...
    Rada

  • Problem with Multiple record creation using BAPI BAPI_PRICES_CONDITION

    Hi,
    I am working on IS Media Sales And Distribution wherein i am using BAPI BAPI_PRICES_CONDITION for condition record creation in TCODE JC9B. I am able to create one record using this BAPI for one sales promotion but having problem while creation of multiple records for the same sales promotion wherein my internal table have multiple records. It gives me error that data in BAPICONDIT is missing.
    I am aatching followig code for reference
    BAPI have field of varkey which i am filling as combination of sales org. + distn channel + sales promotion + delivery type
    In this varkey  delivery type is changing for sales promotion Can be said that one sales promotion can have multiple delivery type .
    Am i giving the correct varkey for each itration of internal table ?
    I am attaching code for reference.
    Here loop it_cond contain one promotion and multiple delivery type.
    sales org   distn ch  promotion     delivery
    0100             01        zsalesprom   03
    0100             01        zsalesprom   z3
      LOOP AT it_cond INTO wa_cond.
    Get next condition number
          CALL FUNCTION 'NUMBER_GET_NEXT'
            EXPORTING
              nr_range_nr                   = '01'
              object                        = 'KONH'
      QUANTITY                      = '1'
      SUBOBJECT                     = ' '
      TOYEAR                        = '0000'
      IGNORE_BUFFER                 = ' '
           IMPORTING
              number                        = number
      QUANTITY                      =
      RETURNCODE                    =
    EXCEPTIONS
      INTERVAL_NOT_FOUND            = 1
      NUMBER_RANGE_NOT_INTERN       = 2
      OBJECT_NOT_FOUND              = 3
      QUANTITY_IS_0                 = 4
      QUANTITY_IS_NOT_1             = 5
      INTERVAL_OVERFLOW             = 6
      BUFFER_OVERFLOW               = 7
      OTHERS                        = 8
          IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
    Here i am concacating varkey for each new delivery
    CLEAR : l_min,l_length,l_var.
    CONCATENATE wa_cond-vkorg wa_cond-vtweg wa_cond-wrbakt INTO l_var.
    l_length = STRLEN( l_var ).
    IF l_var+14(2) IS INITIAL.
    WRITE wa_cond-lifart TO L_VAR+14.
    l_length = STRLEN( l_var ).
    ENDIF.
    W_LINE = W_LINE + 1.
    *First table in BAPI
            wa_bapicondct-operation = '009'.
            wa_bapicondct-cond_usage = 'A'.
            wa_bapicondct-table_no = '506'.
            wa_bapicondct-applicatio = 'J0'.
            wa_bapicondct-cond_type = 'RATE'.
            wa_bapicondct-varkey = l_var.
            wa_bapicondct-valid_to = wa_cond-datbi.
            wa_bapicondct-valid_from = wa_cond-datab.
            wa_bapicondct-cond_no = number. "
            APPEND wa_bapicondct TO it_bapicondct.
    *Second table in BAPI
            wa_bapicondhd-operation = '009'.
            wa_bapicondhd-cond_no = number.
            wa_bapicondhd-cond_usage = 'A'.
            wa_bapicondhd-table_no = '506'.
           wa_bapicondhd-created_by = sy-uname.
           wa_bapicondhd-creat_date = sy-datum.
            wa_bapicondhd-applicatio = 'J0'.
            wa_bapicondhd-cond_type = 'RATE'.
            wa_bapicondhd-varkey = l_var.
            wa_bapicondhd-valid_from = wa_cond-datab.
            wa_bapicondhd-valid_to = wa_cond-datbi.
            APPEND wa_bapicondhd TO it_bapicondhd.
    *Third table in BAPI
            wa_bapicondit-operation = '009'.
            wa_bapicondit-cond_no = number.
            wa_bapicondit-cond_count = wa_cond-cond_count.
            wa_bapicondit-applicatio = 'J0'.
            wa_bapicondit-cond_type = 'RATE'.
            wa_bapicondit-calctypcon = 'C'.
           wa_bapicondit-scaletype  = 'A'.
            wa_bapicondit-cond_value = wa_cond-kbetr.
            wa_bapicondit-condcurr = wa_cond-konwa.
            wa_bapicondit-promotion = wa_cond-wrbakt.
            APPEND wa_bapicondit TO it_bapicondit.
    *Fourth table in BAPI
            wa_bapicondqs-operation = '009'.
            wa_bapicondqs-cond_no = number.
            wa_bapicondqs-cond_count = wa_cond-cond_count.
            wa_bapicondqs-currency = wa_cond-kbetr.
            wa_bapicondqs-condcurr = wa_cond-konwa.
           wa_bapicondqs-cond_unit = 'EA'.
            wa_bapicondqs-LINE_NO = W_LINE."'0001'.
            APPEND wa_bapicondqs TO it_bapicondqs.
    *Fifth table in BAPI
            wa_bapicondvs-operation = '009'.
            wa_bapicondvs-cond_no = number.
            wa_bapicondvs-cond_count = wa_cond-cond_count.
            wa_bapicondvs-currenckey = wa_cond-konwa.
            wa_bapicondvs-currenciso = wa_cond-konwa.
           wa_bapicondvs-currency = wa_cond-kbetr.
           wa_bapicondvs-condcurr = wa_cond-konwa.
           wa_bapicondvs-curren_iso = wa_cond-konwa.
           wa_bapicondvs-LINE_NO = W_LINE."'0001'.
            APPEND wa_bapicondvs TO it_bapicondvs.
            CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
    EXPORTING
      PI_INITIALMODE       = ' '
      PI_BLOCKNUMBER       =
              TABLES
                ti_bapicondct        = it_bapicondct
                ti_bapicondhd        = it_bapicondhd
                ti_bapicondit        = it_bapicondit
                ti_bapicondqs        = it_bapicondqs
                ti_bapicondvs        = it_bapicondvs
                to_bapiret2          = it_bapiret2
                to_bapiknumhs        = it_bapiknumhs
                to_mem_initial       = it_cnd_mem_initial
             EXCEPTIONS
               update_error         = 1
               OTHERS               = 2
            IF sy-subrc <> 0.
              MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
            ENDIF.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
             EXPORTING
               wait          = 'X'
    IMPORTING
      RETURN        =
            CLEAR : wa_bapicondct,wa_bapicondhd,wa_bapicondvs,wa_bapicondqs.
            CLEAR : wa_bapicondit.
          ENDLOOP.
        ENDIF.
      ENDIF.
    Kindly Suggest.
    Thanks
    Parag

    Solved By myself
    There is problem while passing data to internal table for item level

  • Left outer join 3 tables with where-statement

    Hi folks,
    I hope you can understand (and maybe solve) my problem.
    Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
    The three table structures are the following:
    table 1 (user)   
    user1 | key
    table 2 (detail)  
    key | ID
    table 3 (header)
    ID | user2                 
    ...and I want to achieve the following structure (as example filled with data):
    user | key | ID
    |-----|----
    xy    | a    | 001
    xy    | b    | #
    z     | b     | #
    The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
    1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
    2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
    I tried this coding:
    SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
      LEFT OUTER JOIN table2 AS b ON akey = bkey )
      LEFT OUTER JOIN table3 AS c ON bID = cID )
      WHERE auser1 = cuser2.
    I would really appreciate your help.
    Regards
    MrclSpdl

    IF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
    select dbfields
    into table itab2
    from dbtab
    for all entries in itab
    where dbfield1 = itab-field1.
    This will get you a second internal table with all the corresponding data for the first selection.  You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation).  Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
    Regards,
    Freek

  • How to isolate error with a record/segment in IDOC with multiple records

    I have an IDOC with multiple records/segments (typically 1000 records/segments). Sometime XI can not process the IDOC because of some control characters in data.
    1. How can I pre-processed the IDOC to remove those control characters?
    Can I use XPATH expression/Java class to do it? How can I configure the XPATH expression/Java class in XI to pre-process the file?
    2. Until I have answer to 1st question. I would like to find out the error is exactly for which record? What configuration can I do in XI to isolate the error is with which record/segment in IDOC?
    Thanks in advance.

    Split the IDoc.
    with in the UDF, after the validations if every thing fine, pass as successful records to success_MT and pass it to target system using Branching in BPM.
    if errors found in the record, then store the error records in Hash table with in UDF, get the IDoc number, frame as a string and raise alert.
    U have to do this in the context of IDoc.
    If U wanna get the IDoc Number, Segment Name and field name for every failure, U can pass the expected error field name as constant to UDF, frame the sentence in the UDF like -> <b>IDoc 1234321 segment – SEG001 – field – FLD03 has a special character ‘*’</b>.
    If U wanna pass this string to source/target, U can do in error messages branch in BPM.
    U must use BPM for splitting the IDoc, since it is multi-mapping.
    reg.,
    Yallabandi.

  • Can we bind a single external table with multiple files in OWB 11g?

    Hi,
    I wanted to ask if it is possible to bind an external table with multiple source files at same or different locations? Or an external table has to be bound to a single source file and a single location.
    Thanks in advance,
    Ann.
    Edited by: Ann on Oct 8, 2010 9:38 AM

    Hi Ann,
    Can you please help me out by telling me the steps to accomplish this. Right click on the external table in project tree, from the menu choose Configure,
    then in opened Configuration Properties dialog window right clock on Data Files node and choose from menu Create -
    you will get new record for file - specify Data File Name property
    Also link from OWB user guide
    http://download.oracle.com/docs/cd/B28359_01/owb.111/b31278/ref_def_flatfiles.htm#i1126304
    Regards,
    Oleg

  • Flat File with multiple record types (OWB 10.2.0.2)

    Hi!
    I`m using OWB 10.2.0.2 and I`m trying to load a flat file with multiple record types, using SQL LOADER.
    In the flat file editor in the Record tab, I`ve set the type values and the corresponding record names like this:
    Type Value Record Name
    ======== ===========
    T TRAILER
    0 DETAILS
    1 DETAILS
    2 DETAILS
    When using this flat file in a mapping to load the data in a staging table, the generated code looks like this:
    INTO TABLE TRAILER
    TRUNCATE
    REENABLE DISABLED_CONSTRAINTS
    WHEN (1:1) = 'T'
    INTO TABLE DETAILS
    APPEND
    REENABLE DISABLED_CONSTRAINTS
    WHEN (1:1) = '0,1,2'
    The above clause (WHEN (1:1) = '0,1,2') is wrong as I expect one "INTO TABLE..." clause for each record type.
    Could this be a bug or am I doing something wrong?
    Thanks a lot for your help,
    Yorgos

    We`re using two target tables, one for the trailer record and the other for the details records.
    We are facing this problem from the moment we upgraded from OWB 10.1 to OWB 10.2.0.2, so we think it must be something with the way the sql loader code is generated in the new version.
    As our data sources are mainly flat files coming from mainframes, this is a huge problem for us. We even asked an expert in DW from Oracle to help us on this, but still haven`t found a solution.
    Is there any workaround for this or should we forget sql loader and go with an external tables + custom PL/SQL code solution?
    Your help is greatly appreciated Jean-Pierre.
    Regards,
    Yorgos

  • Joining 3 tables with null values

    Hi,
    I have three tables that have varying data in. I want to write a query which will list all three in the result set, but when one of the tables doesn't have a row, write in No Value.
    I will be intending on joining the tables with account numbers. What will be the syntax of a join with three tables where I am not sure which table will have null values?
    Thanks...

    Something like
    select nvl(a.id,'No Value'), nvl(b.id, 'No Value'), nvl(C.id, 'No Value')
       from (select id from t1) a,
                  (select id from t2) b,
                  (select id from t3) c
      where a.id = b.id(+)
          and a.id = c.id(+)
    Hi,
    I have three tables that have varying data in. I want to write a query which will list all three in the result set, but when one of the tables doesn't have a row, write in No Value.
    I will be intending on joining the tables with account numbers. What will be the syntax of a join with three tables where I am not sure which table will have null values?
    Thanks...

  • Code to Join three tables.

    Hi All,
    I am a fresher to this ABAP.
    I have an task to join three tables which doesn't take much effort. But the problem is: the tables have same columns, (name, age and city) in all the three tables.
    The layout is as shown below:
    Table 1  ( T1 )            Table 2  ( T2 )          Table 3 ( T3 )
      name | age | city      name | age | city        name | age | city    -
    Anju   21     HDD      Anju   20     BGH       Anju    21    SFF
    Julie   23     JUH       Julie   24     JUH        Julie   20     JUH
    Now, there should be a selection screen. If I enter a value for this varaible as "Anju", The output should be like:
    Col       T1        T2      T3
    Name    Anju     Anju    Anju
    Age       21        20       21
    City       HDD    BGH    SFF
    I am unable to appraoch how to solve this issue. Any pointers would be of great help.
    Thanks in advance,
    Anjum.
    Edited by: nasarat anjum on Apr 23, 2008 8:43 AM

    Hi,
    U can take three internal tables for each of ur tables T1,T2,T3. Fetch the respective table data into ur internal tables.
    Then write,
    loop at itab1.
    read table itba2 with key name eq itab1-name.
    read table itab3 with key name eq itab1-name.
    write : / name under <name heading>,
                itab1-name under <T1 heading>,
                itab2-name under <T2 heading>,
                itab3-name under <T3 heading>.
    write : / age under <age heading>,
                itab1-age under <T1 heading>,
                itab2-age under <T2 heading>,
                itab3-age under <T3 heading>.
    write : / city under <city heading>,
                itab1-city under <T1 heading>,
                itab2-city under <T2 heading>,
                itab3-city under <T3 heading>.
    <removed by moderator>
    Thanks
    Edited by: Mike Pokraka on Aug 6, 2008 8:30 AM

  • Editable table with multiple rows

    Hi All!
    We're trying to develop some application in VC 7.0. That application should read data from some R/3 tables (via standard and custom functional modules), then display data to user and allow him/her to modify it (or add some data into table rows), and then save it back to R/3.
    What is the best way to do that?
    There's no problem with displaying data.
    But when I try to add something to table (on portal interface), I'm able to use only first row of the table... Even if I fill all fields of that row, I'm not able to add data to second row, etc.
    Second question. Is it possible to display in one table contents of output of several BAPIs? For example we have three bapis, one displaying user, second displays that user's subordinates, and the third one - that user's manager. And we want one resulting table...
    And last. What is the best way to submit data from table view in VC (portal) to R/3 table? I understand that we should write some functional module, that puts data to R/3. I'm asking about what should be done in VC itself. Some button, or action...
    Any help will be appreciated and rewarded :o)
    Regards,
    DK

    Here are some former postings:
    Editable table with multiple rows
    and
    Editable table with multiple rows
    Are you on the right SP-level?
    Can you also split up your posting: one question, one posting? This way you get faster answers, as people might just browse the headers.

  • Web Analysis : populate the same table with multiple data sources

    Hi folks,
    I would like to know if it is possible to populate a table with multiple data sources.
    For instance, I'd like to create a table with 3 columns : Entity, Customer and AvgCostPerCust.
    Entity and Customer come from one Essbase, AvgCostPerCust comes from HFM.
    The objective is to get a calculated member which is Customer * AvgCostPerCust.
    Any ideas ?
    Once again, thanks for your help.

    I would like to have the following output:
    File 1 - Store 2 - Query A + Store 2 - Query B
    File 2 - Store 4 - Query A + Store 4 - Query B
    File 3 - Store 5 - Query A + Store 5 - Query B
    the bursting level should be give at
    File 1 - Store 2 - Query A + Store 2 - Query B
    so the tag in the xml has to be split by common to these three rows.
    since the data is coming from the diff query, and the data is not going to be under single tag.
    you cannot burst it using concatenated data source.
    But you can do it, using the datatemplate, and link the query and get the data for each file under a single query,
    select distinct store_name from all-stores
    select * from query1 where store name = :store_name === 1st query
    select * from query2 where store name = :store_name === 2nd query
    define the datastructure the way you wanted,
    the xml will contain something like this
    <stores>
    <store> </store> - for store 2
    <store> </store> - for store 3
    <store> </store> - for store 4
    <store> </store> - for store 5
    <stores>
    now you can burst it at store level.

Maybe you are looking for

  • My brand new iPod Touch 4th Generation, just isn't functioning correctly.

    Recently, I bought a brand new iPod 4th gen. Since, it has gone haywire and refuses to function correctly. It is 16 gb and operating on iOS 6.0.1. On many apps, especially games, it can get really laggy at times, for no discernable reason. I have ver

  • SQL STATEMENT , PLEASE HELP

    Hi, I want some help in writing a SQL Query .Its besically a hierarchical query. Let me lay down the table structure first to explain my requirements better. PORP_TABLE(NODE_LEVEL int, WBS_ID int, WBS_NUMBER varchar(60), LFT int,RGT int) SELECT NODE_

  • Search results are differed in Quick and candidate searches

    Hi Everyone, I am using ECC 6  EhP 5 system with Trex search 7.10.48. We are having a scenario where search is behaving differently in different places. We are able to find some  Locked  candidates in quick Search (ERC_C_QUICK_SEARCH_UI) as well as i

  • Screen Exit for ME21

    I have created a screen exit using enhancement AMPL0001 , I have created cl_includes (structure) coded in the function exits for pbo and pai. created subscreen 1000 as given in the enhancement . But the filed is not getting displayed ???

  • I am getting an error downloading iOS 6 for iPad 2

    What do I need to do for the above scenario?