THE SQL Server Blog Spot on the Web
Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | Join | Help
in Search

Need to export data from joining two tables from one database to a table residing in another database

Last post 06-13-2008, 0:38 by money2184. 2 replies.
Sort Posts: Previous Next
  •  05-31-2008, 14:00 7092

    Need to export data from joining two tables from one database to a table residing in another database

    Hi All,

       Following is the secnario,                 

    I have two tables one is dimension table and other is hierarchy table, which contains the following type of data

    Dimension Table

    MemberID Label

    NULL       NONE

    1              A

    2              B

    3              C

    4              D

    5              E

    6              F

    Hierarchy Table contains the following

    MemberID ParentMemberID

    1                  NULL

    2                    1

    3                    1

    4                    2

    5                    4

    6                   5

    Now by joining the above two tables i want to populate the other table which contains the

    following columns,

    Label ParentLabel

    The data for the above table should look like following

    Label ParentLabel

    A         NULL

    B          A

    C          A

    D          B

    E          D

    F          E

     

    Please help me in achieving the above scenario

     

     

                

     

    Filed under:
  •  06-03-2008, 9:45 7113 in reply to 7092

    Re: Need to export data from joining two tables from one database to a table residing in another database

    Here is one way:

     

    SELECT

      d.Label,

      d1.Label AS ParentLabel

    FROM DimensionTable d

    LEFT OUTER JOIN HierarchyTable h ON d.MemberId = h.MemberId

    LEFT OUTER JOIN DimensionTable d1 ON d1.MemberId = h.ParentMemberId

     

  •  06-13-2008, 0:38 7276 in reply to 7092

    Re: Need to export data from joining two tables from one database to a table residing in another database

    Thanks Adam Machanic is not online. Last active: 06-10-2008, 18:40 Adam Machanic  : )
Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement