Retrive data from two tables

Hi ,
I have two tables, we want to retrive data from both the tables please see example below
Table 1
A B X Y Z
1 2
Table B
A B C
1 2 5
1 2 6
1 2 7
I want output like
A B C
1 2 5
Null Null 6
Null Null 7
Regards
Message was edited by:
rajib.sarkar

Could you explain the logic behind that?

Similar Messages

  • Retrive data from two tables into one internal table.

    Hi SDN,
    I am downloading the Assets data from two tables ANLA,ANLZ.
    there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
    can you please send me the SELECT Syntax for this probl.....
    Thank you & Regards,
    Manoj

    Hi manoj,
    Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
    data: begin of itab occurs 0,
            BUKRS like anla-BUKRS,
            ANLN1 like anla-ANLN1,
           BDATU like anlz-BDATU,
            end of itab.
    select anlabukrs anlaANLN1 anlzBDATU  into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
    Please come back for any clarification.
    Thanks and Regards,
    saurabh

  • Retriving data  from two tables at a time.

    Please use this forum to provide feedback about OTN content/services. All other posts will be DELETED.
    hi all,
    Am using win98 and Oracle 7.
    I have splitted a table into two tables having 10 and 9 fields respectively and records of 2000.Now in form builder I have put both tables in same block and on same canvas.
    Now when I execute a query I retrieve records of 1st table and can navigate through records of 1st table only .To retrive records of 2nd table I have to put curser in 2nd table and query again for data retrival from 2nd table.This is bothering me to match coulmn of both tables.
    Is there any way to execute the records of both tables at a time, so that matching coulmns of both tables would become easy to reach.
    Thanks and Regards

    heeeey mohammad
    you have first to make master/detail block not one block only
    then jion between them as pk and fk

  • Unable to retrive data from two tables using multiple joins

    Hi,
    Table:   EMP mgr 
    eid              name
    eid mgrid
    1
    A 1
    null
    2
    B 2
    3
    3
    C 3
    3
    i need to get result as:
    eid ename mgrname
    thanks
    AVS

    Sai,
    It would be very helpful if you could mention your table structures a bit more clearly. Would allow for effective replies from fellow users as well. :) 
    However, assuming that your structure would be as follows presenting the query as below:
    DECLARE @Emp TABLE(Eid Int, ename Varchar(50))
    DECLARE @Emp_Mgr TABLE(Eid int, mgrid int null )
    INSERT INTO @Emp select 1,'Ram'
    INSERT INTO @Emp select 2,'Shyam'
    INSERT INTO @Emp_Mgr select 1,NULL
    INSERT INTO @Emp_Mgr select 2,1
    SELECT * FROM @Emp
    SELECT * FROM @Emp_Mgr
    Query to print results as EID, ENAME, MGRNAME
    SELECT em.eid,e1.ename as ENAME,e2.ename as MGRNAME
    FROM @Emp_Mgr em
    JOIN @Emp e1 ON em.eid=e1.eid
    JOIN @Emp e2 ON em.mgrid=e2.eid
    However, as you see this approach of maintaining two tables for preserving the employee-manager data is redundant and makes the queries unnecessarily complex. So, you could opt for the widely used single table format as mentioned by Praveen as well. Check
    if this helps you..
    Recommended Structure
    *Avoidance of redundant storage of data
    *Lesser Joins in queries
    DECLARE @Emp TABLE(Eid Int , Ename Varchar(50) , mgrid int null )
    INSERT INTO @Emp(Eid , ename , mgrid) values(1 , 'Ram' , null) , (2 , 'Shyam' , 1)
    SELECT * FROM @Emp
    Query to print results as EID, ENAME, MGRNAME
    SELECT e.Eid , e.Ename , m.Ename as MgrName
    FROM @Emp e
    JOIN @Emp m On a.mgrid = b.eid
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • To Select the data from two table one is transp table and onther is cluster

    Hi All,
    I want to select the data from two tables
    Here i am giving with an example.
    Fileds: kunnr belnr from bseg.  table bseg
    fields: adrnr from kna1     table: kna1.
    Know i want to put these into one internal table based on kunnr and belnr.
    Thanks in advance.
    Ramesh

    Hi,
       U cant use joins on cluster table and BSEG is a cluster table so use FOR  ALL ENTRIES for taht
    refer this code
    *&      Form  sub_read_bsak
          text
    -->  p1        text
    <--  p2        text
    FORM sub_read_bsak.
    *--Select data from BSAK Table
      SELECT lifnr
             augdt
             augbl
             gjahr
             belnr
             xblnr
             blart
             dmbtr
             mwskz
             mwsts
             sgtxt
             FROM bsak
             INTO CORRESPONDING FIELDS OF TABLE it_bsak
             WHERE belnr IN s_belnr
             AND   augdt IN s_augdt.
      IF sy-subrc EQ 0.
    *--Sort table by accounting document and vendor number
        SORT it_bsak BY belnr lifnr.
      ENDIF.
    ENDFORM.                    " sub_read_bsak
    *&      Form  sub_read_bseg
          text
    -->  p1        text
    <--  p2        text
    FORM sub_read_bseg.
      IF NOT it_bsak[] IS INITIAL.
    *--Select data from BSEG table
        SELECT belnr
               gjahr
               shkzg
               kostl
               hkont
               ebeln
               ebelp
               FROM bseg
               INTO CORRESPONDING FIELDS OF TABLE it_bseg
               FOR ALL ENTRIES IN it_bsak
               WHERE belnr EQ it_bsak-belnr
               AND   gjahr EQ it_bsak-gjahr
               AND   shkzg EQ 'S'.
        IF sy-subrc EQ 0.
    *--Sort table by accounting document
          SORT it_bseg BY belnr.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_read_bseg

  • Cartesian of data from two tables with no matching columns

    Hello,
    I was wondering – what’s the best way to create a Cartesian of data from two tables with no matching columns in such a way, so that there will be only a single SQL query generated?
    I am thinking about something like:
    for $COUNTRY in ns0: COUNTRY ()
    for $PROD in ns1:PROD()
    return <Results>
         <COUNTRY> {fn:data($COUNTRY/COUNTRY_NAME)} </COUNTRY>
         <PROD> {fn:data($PROD/PROD_NAME)} </PROD>
    </Results>
    And the expected result is combination of all COUNTRY_NAMEs with all PROD_NAMEs.
    What I’ve noticed when checking query plan is that DSP will execute two queries to have the results – one for COUNTRY_NAME and another one for PROD_NAME. Which in general results in not the best performance ;-)
    What I’ve noticed also is that when I add something like:
    where COUNTRY_NAME != PROD_NAME
    everything is ok and there is only one query created (it's red in the Query plan, but still it's ok from my pov). Still it looks to me more like a workaround, not a real best approach. I may be wrong though...
    So the question is – what’s the suggested approach for such queries?
    Thanks,
    Leszek
    Edited by xnts at 11/19/2007 10:54 AM

    Which in general results in not the best performanceI disagree. Only for two tables with very few rows, would a single sql statement give better performance.
    Suppose there are 10,000 rows in each table - the cross-product will result in 100 million rows. Sounds like a bad idea. For this reason, DSP will not push a cross-product to a database. It will get the rows from each table in separate sql statements (retrieving only 20,000 rows) and then produce the cross-product itself.
    If you want to execute sql with cross-products, you can create a sql-statement based dataservice. I recommend against doing so.

  • Select data from two tables...!

    HI Experts...!
    i m a beginner user and i want to select data from two tables proj and prps.....using joins.....and internal tables i have written a code...
    SELECT prps~pspnr
           prps~objnr
           prps~psphi
           proj~ernam
           proj~erdat
           proj~pspnr
    INTO  table itab   -
    itab is internal table
    FROM prps inner join proj
    WHERE pspnr in p_no and prpspsphi = projpspnr.
    but there is error in from clause ..please help me....
    Advance thanx....

    Hi,
    check the sample code bellow above two reply will solve out your problem but one more extra line in your code pointed out bellow.
    TABLES: prps, proj.
    TYPES:  BEGIN OF ty_test,
            pspnr LIKE prps-pspnr,
            objnr LIKE prps-objnr,
            psphi LIKE prps-psphi,
            ernam LIKE proj-ernam,
            erdat LIKE proj-erdat,
            END OF ty_test.
    DATA: itab TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
    SELECT-OPTIONS: p_no FOR prps-pspnr.
    SELECT  prps~pspnr
            prps~objnr
            prps~psphi
            proj~ernam
            proj~erdat
    *        proj~pspnr " No need for this you have selected this in
    *     the first line because it is commone so you only need to select from any one
            INTO TABLE itab
    FROM prps INNER JOIN proj ON ( prps~pspnr = proj~pspnr  )
    WHERE prps~pspnr IN p_no.
    Best Regards,
    Faisal
    Edited by: Rob Burbank on Dec 24, 2009 12:24 PM

  • Creating a external content type for Read and Update data from two tables in sqlserver using sharepoint designer

    Hi
    how to create a external content type for  Read and Update data from two tables in  sqlserver using sharepoint designer 2010
    i created a bcs service using centraladministration site
    i have two tables in sqlserver
    1)Employee
    -empno
    -firstname
    -lastname
    2)EmpDepartment
    -empno
    -deptno
    -location
    i want to just create a list to display employee details from two tables
    empid firstname deptno location
    and same time update  in two tables
    adil

    When I try to create an external content type based on a view (AdventureWorks2012.vSalesPerson) - I can display the data in an external list.  When I attempt to edit it, I get an error:
    External List fails when attached to a SQL view        
    Sorry, something went wrong
    Failed to update a list item for this external list based on the Entity (External Content Type) 'SalesForce' in EntityNamespace 'http://xxxxxxxx'. Details: The query against the database caused an error.
    I can edit the view in SQL Manager, so it seems strange that it fails.
    Any advice would be greatly GREATLY appreciated. 
    Thanks,
    Randy

  • Selecting data from two tables

    I am trying to select data from two tables.  The only problem that I am running into, is that i am only seeing results from my 'uploads' table.  there is also a record in documents where user = 1 that should show up.  here is my sql:
    $userIDNum = 1;
    $sql="Select *
    from uploads, documents
    WHERE uploads.user = documents.user AND uploads.user = $userIDNum
    ORDER BY uploads.title ASC, documents.title ASC";

    You'll need to explain a little more about your data and what you are trying to accomplish. Your current sql will select all columns from both the uploads and documents tables but only rows where the user id in both tables match, AND the user id equals 1. Is that not what you are seeing? Where's the code that outputs the results?

  • Fetch the data from two tables

    hell all
    i want to fetch the data from two tables, one is from internal table and another one is data base table. what syntax i have to use either FOR ALL ENTRIES or INNER JOIN?

    hi
    Use FOR ALL ENTRIES.
    see the sample code
      select * into table tvbrk from vbrk
                                where fkart in ('F2', 'F3', 'RE',
                                           'ZVEC' , 'ZVEM' , 'ZVED',
                                           'S1')
                                and erdat in so_erdat
                                and kunag in s_kunag. 
                                      erdat in so_erdat
                               and   fkart in ('F2', 'F3', 'RE',
                                                 'ZVEC' , 'ZVEM').
    if not tvbrk is initial.
        select * into table t_zregion from zregion
                      for all entries in tvbrk
                       where country = tvbrk-land1
                       and   region = s_regio.
      endif.
    thanks
    sitaram

  • Populate ADF Rich Table taking data from two tables of database

    Hi,
    Can anyone please guide me as to how I can populate ADF Rich Table taking data from two tables A and B of a database.
    The condition is
    I want to fetch row 1 from table A and populate into ADF Rich Table at row 1
    then
    I want to fetch row 1 from table B and populate into ADF Rich Table at row 2
    and so on....
    Many thanks for your help..
    Regards,
    Rohit

    The better place where you will learn:
    http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/bcquerying.htm

  • Retrive data from HR tables

    Hi Experts,
    How to retrive data from HR tables for custom screen & store in custom table? I need Employee number, employee name, department, their location & mail id. When employee number is given, all other details must be fetched. Can you give a solution for this problem?
    Thanks,
    Kavitha

    Hi Kavitha,
    in HR you could get data from different tables based on infotypes. lets say if any data need to get from infotype 0001 (Org assignment), add "PA" before the infotype number so it would be PA0001.
    you could get the Employee no, name, department, location(i guess personal area or personal subarea) from PA0001 table and email id from PA105 infotype.
    Regards
    Raju

  • Retrive data from 4 tables without using joins

    hi ,
    i have to retrive data from 4 tables........but i donot want to use joins because of performance issues.
    please guide me how to proceed further ?
    thanks

    hi manish,
    CONSTANTS: c_act_plan(2)    TYPE c VALUE 'U1'      ,
               c_person(1)      TYPE c VALUE 'P'       ,
               p1_betid(8)      TYPE c VALUE '50005316',
               c_topdown(1)     TYPE c VALUE 'A'       ,
               c_admnby(3)      TYPE c VALUE '032'     ,
               c_bet_type(1)    TYPE c VALUE 'Q'       ,
               c_firmed(1)      TYPE c VALUE '1'       ,
               c_subtyp_mail(4) TYPE c VALUE '0001'    .
    TYPES: BEGIN OF ty_hrp1001,
             objid TYPE hrp1001-objid,
           END OF ty_hrp1001,
           BEGIN OF ty_pa0001,
             pernr TYPE pa0001-pernr,
             subty TYPE pa0001-subty,
             objps TYPE pa0001-objps,
             sprps TYPE pa0001-sprps,
             endda TYPE pa0001-endda,
             begda TYPE pa0001-begda,
             seqnr TYPE pa0001-seqnr,
             werks TYPE pa0001-werks,
             gsber TYPE pa0001-gsber,
             btrtl TYPE pa0001-btrtl,
           END OF ty_pa0001,
           BEGIN OF ty_t500p,
             persa TYPE t500p-persa,
             name1 TYPE t500p-name1,
           END OF ty_t500p,
           BEGIN OF ty_t001p,
             werks TYPE t001p-werks,
             btrtl TYPE t001p-btrtl,
             btext TYPE t001p-btext,
           END OF ty_t001p,
           BEGIN OF ty_pa0002,
             pernr TYPE pa0002-pernr,
             subty TYPE pa0002-subty,
             objps TYPE pa0002-objps,
             sprps TYPE pa0002-sprps,
             endda TYPE pa0002-endda,
             begda TYPE pa0002-begda,
             seqnr TYPE pa0002-seqnr,
             nachn TYPE pa0002-nachn,
             vorna TYPE pa0002-vorna,
           END OF ty_pa0002,
           BEGIN OF ty_pa0105,
             pernr      TYPE pa0105-pernr     ,
             subty      TYPE pa0105-subty     ,
             objps      TYPE pa0105-objps     ,
             sprps      TYPE pa0105-sprps     ,
             endda      TYPE pa0105-endda     ,
             begda      TYPE pa0105-begda     ,
             seqnr      TYPE pa0105-seqnr     ,
             usrid_long TYPE pa0105-usrid_long,
           END OF ty_pa0105,
           BEGIN OF ty_output,
             pernr      TYPE pa0002-pernr     ,
             werks      TYPE pa0001-werks     ,
             gsber      TYPE pa0001-gsber     ,
             btrtl      TYPE pa0001-btrtl     ,
             name1      TYPE t500p-name1      ,
             btext      TYPE t001p-btext      ,
             nachn      TYPE pa0002-nachn     ,
             vorna      TYPE pa0002-vorna     ,
             usrid_long TYPE pa0105-usrid_long,
           END OF ty_output.
    DATA: w_hrp1001     TYPE                 ty_hrp1001,
          t_hrp1001     TYPE        TABLE OF ty_hrp1001,
          t_hrp1001_tmp TYPE        TABLE OF ty_hrp1001,
          w_pa0001      TYPE                 ty_pa0001 ,
          t_pa0001      TYPE SORTED TABLE OF ty_pa0001
            WITH NON-UNIQUE KEY pernr                  ,
          t_pa0001_tmp  TYPE        TABLE OF ty_pa0001 ,
          w_t500p       TYPE                 ty_t500p  ,
          t_t500p       TYPE HASHED TABLE OF ty_t500p
            WITH UNIQUE KEY persa                      ,
          w_t001p       TYPE                 ty_t001p  ,
          t_t001p       TYPE HASHED TABLE OF ty_t001p
            WITH UNIQUE KEY werks btrtl                ,
          w_pa0002      TYPE                 ty_pa0002 ,
          t_pa0002      TYPE SORTED TABLE OF ty_pa0002
            WITH NON-UNIQUE KEY pernr                  ,
          t_pa0002_tmp  TYPE        TABLE OF ty_pa0002 ,
          w_pa0105      TYPE                 ty_pa0105 ,
          t_pa0105      TYPE SORTED TABLE OF ty_pa0105
            WITH NON-UNIQUE KEY pernr                  ,
          w_output      TYPE                 ty_output ,
          t_output      TYPE        TABLE OF ty_output .
    SELECT objid
      FROM hrp1001
      INTO TABLE t_hrp1001
      WHERE otype EQ c_person
      AND   plvar EQ c_act_plan
      AND   rsign EQ c_topdown
      AND   relat EQ c_admnby
      AND   istat EQ c_firmed
      AND   begda LE sy-datum
      AND   endda GT sy-datum
      AND   sclas EQ c_bet_type
      AND   sobid EQ p1_betid.
    IF sy-subrc EQ 0.
      SORT t_hrp1001 BY objid.
    ENDIF.
    IF NOT t_hrp1001[] IS INITIAL.
      t_hrp1001_tmp[] = t_hrp1001[].
      DELETE ADJACENT DUPLICATES FROM t_hrp1001_tmp
        COMPARING objid.
      SELECT pernr
             subty
             objps
             sprps
             endda
             begda
             seqnr
             werks
             gsber
             btrtl
        FROM pa0001
        INTO TABLE t_pa0001
        FOR ALL ENTRIES IN t_hrp1001_tmp
        WHERE pernr EQ t_hrp1001_tmp-objid
        AND   endda GT sy-datum
        AND   begda LE sy-datum.
      SELECT pernr
             subty
             objps
             sprps
             endda
             begda
             seqnr
             nachn
             vorna
        FROM pa0002
        INTO TABLE t_pa0002
        FOR ALL ENTRIES IN t_hrp1001_tmp
        WHERE pernr EQ t_hrp1001_tmp-objid
        AND   endda GT sy-datum
        AND   begda LE sy-datum.
    ENDIF.
    IF NOT t_pa0001[] IS INITIAL.
      t_pa0001_tmp[] = t_pa0001[].
      SORT t_pa0001_tmp BY werks btrtl.
      DELETE ADJACENT DUPLICATES FROM t_pa0001_tmp COMPARING werks btrtl.
      SELECT werks
             btrtl
             btext
        FROM t001p
        INTO TABLE t_t001p
        FOR ALL ENTRIES IN t_pa0001_tmp
        WHERE werks EQ t_pa0001_tmp-werks
        AND   btrtl EQ t_pa0001_tmp-btrtl.
      DELETE ADJACENT DUPLICATES FROM t_pa0001_tmp COMPARING werks.
      SELECT persa
             name1
        FROM t500p
        INTO TABLE t_t500p
        FOR ALL ENTRIES IN t_pa0001_tmp
        WHERE persa EQ t_pa0001_tmp-werks.
    ENDIF.
    IF NOT t_pa0002[] IS INITIAL.
      t_pa0002_tmp[] = t_pa0002[].
      DELETE ADJACENT DUPLICATES FROM t_pa0002_tmp COMPARING pernr.
      SELECT pernr
             subty
             objps
             sprps
             endda
             begda
             seqnr
             usrid_long
        FROM pa0105
        INTO TABLE t_pa0105
        FOR ALL ENTRIES IN t_pa0002_tmp
        WHERE pernr EQ t_pa0002_tmp-pernr
        AND   subty EQ c_subtyp_mail
        AND   endda GT sy-datum
        AND   begda LE sy-datum
        AND   usrty EQ c_subtyp_mail.
    ENDIF.
    REFRESH t_output.
    LOOP AT t_hrp1001 INTO w_hrp1001.
      LOOP AT t_pa0001 INTO w_pa0001
        WHERE pernr EQ w_hrp1001-objid.
        READ TABLE t_t500p INTO w_t500p WITH KEY persa = w_pa0001-werks
                                                 TRANSPORTING
                                                   name1.
        CHECK sy-subrc EQ 0.
        READ TABLE t_t001p INTO w_t001p WITH KEY werks = w_pa0001-werks
                                                 btrtl = w_pa0001-btrtl
                                                 TRANSPORTING
                                                   btext.
        LOOP AT t_pa0002 INTO w_pa0002
          WHERE pernr EQ w_hrp1001-objid.
          LOOP AT t_pa0105 INTO w_pa0105
            WHERE pernr EQ w_pa0002-pernr.
            w_output-pernr      = w_pa0002-pernr     .
            w_output-werks      = w_pa0001-werks     .
            w_output-gsber      = w_pa0001-gsber     .
            w_output-btrtl     = w_pa0001-btrtl      .
            w_output-name1      = w_t500p-name1      .
            w_output-btext      = w_t001p-btext      .
            w_output-nachn      = w_pa0002-nachn     .
            w_output-vorna      = w_pa0002-vorna     .
            w_output-usrid_long = w_pa0105-usrid_long.
            APPEND w_output TO t_output.
            CLEAR w_output.
          ENDLOOP.
        ENDLOOP.
      ENDLOOP.
    ENDLOOP.
    Reward if usful,
    Thanks,
    Srikanth.A

  • Data from two tables in the same row in XML transformation

    Hi,
        I am using XML transformation for generating excel file which is to besent as email attachment.
        Here  I want to display the data from two internal tables in the same row in the excel. .I am using   <tt:loop ref=".<table name>"> ...  </tt:loop> for looping through the table. Can I loop two table simultaneously ? In that case how will I specify the fields in each table . Some of the fields in two tables are of same name and type.
    Please help...
    Thanks,
    Jissa

    Hello Brian,
    Thank you for your answer. It is approach I will use, I think. However let me ask: Would it be possible to have a Version in this layout, too? I mean to see, which value comes from Version A and which comes from Version B? Something like this:
    Calendar Month Version Sales Amount
    2011.01  B  200
    2011.02  B  300
    2011.03  A  260
    2011.04  A  230
    2011.05  A  200
    A

  • Fetch data from two tables and insert into one table

    I have similar to the following data in two tables (@Plant, @PlantDirector) and need to consolidate into one table (@PlantNew) as follows.
    DECLARE @Plant TABLE (PlantID INT, PlantName VARCHAR(100))
    INSERT INTO @Plant (PlantID, PlantName) VALUES (1, 'Name One'),(2, 'Name Two'),(3, 'Name Three'),(4, 'Name Four'),(5, 'Name Five'),(6, 'Name Six')
    Director data for the Plants exist in the following table. Assistant value 1 means Assistant Director and 0 means Director. 
    Data exists only for subset of plants and a Plant may have one or both roles.
    DECLARE @PlantDirector TABLE (PlantID INT, PlantDirectorID INT, Assistant bit)
    INSERT INTO @PlantDirector (PlantID, PlantDirectorID, Assistant) VALUES (2, 111, 1),(2, 222, 0),(4, 333, 0),(6,444,1)
    The above data needs to be inserted into one table (@PlantNew) as follows: 
    PlantID in @Plant table is IDENTITY value and needs to be inserted as-is into this table.
    PlantDirExists will get a value of 1 if at least one record exists in @PlantDirector table for a PlantID. PlantAssistantDirID and PlantDirID should be set to the corresponding PlantDirID or NULL appropriately depending on the data.
    DECLARE @PlantNew TABLE (PlantID INT, PlantName VARCHAR(100), PlantDirExists bit, PlantAssistantDirID INT, PlantDirID INT)
    INSERT INTO @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
    VALUES (1, 'Name One', 0, NULL, NULL),(2, 'Name Two', 1, 111, 222),(3, 'Name Three', 0, NULL, NULL),(4, 'Name Four', 1, NULL, 333),(5, 'Name Five', 0, NULL, NULL),(6, 'Name Six',1, 444, NULL)
    How do I achieve the above using SQL ? Thanks.

    like this
    INSERT @PlantNew  (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID) 
    SELECT p.PlantID,
    p.PlantName,
    CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
    PlantAssistantDirID,
    PlantDirID
    FROM @Plant p
    LEFT JOIN (SELECT PlantID,
    MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
    MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
    @PlantDirector
    GROUP BY PlantID)pd
    ON pd.PlantID = p.PlantID
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    You're missing a FROM
    insert into @PlantNew
    SELECT p.PlantID,
    p.PlantName,
    CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
    PlantAssistantDirID,
    PlantDirID
    FROM @Plant p
    LEFT JOIN (SELECT PlantID,
    MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
    MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
    from @PlantDirector
    GROUP BY PlantID)pd
    ON pd.PlantID = p.PlantID

Maybe you are looking for

  • Lookup in a grid

    Hello all.. I have an entity object which represents a table of type: description(VARCHAR),date(Date), Id(Numeric). The Id is FK for table: Id(Numeric PK), Name VARCHAR Now in my application I have a gridControl which should represent table1 but inst

  • Problem with Adobe Acrobat/Reader when opening a Link in Safari???

    For some reason when I'm on a web page that has a link to a PDF file, Safari opens a new window and I get a popup error.  See attached screen shot. Acrobat is not running.  I've tried quitting and re-starting Safari (5.1.7) and even restarting Mac OS

  • Playlist not transferring properly to iPod

    Can anyone tell me why my playlists from my computer are not updating on my iPod? Specifically, I have a playlist "Christmas". There are two songs on my computer list that are not showing up in the same list on my iPod. I have tried syncing numberous

  • Error message on 4506R

    Hi, I have got 2 numbers of 4506 which are connected to the 6500 switch the connectivity to the core switch is over the two different port channel (2 physical interface for each port channel. No I am getting the below error message please let me know

  • Network Link Conditioner to control Wi-Fi

    I just finished installing and testing Network Link Conditioner that comes with Mac OS X Lion and Xcode4.1. It works great locally on the Mac, i.e. when I use the Internet connection that Network Link Condition is limiting directly. However, when I c