Self Join??

  • I have a table that contains

    ID, DESC, PARENT_ID

    I need to end up with

    ID-DESC, PARENT_ID-DESC

    I know how to do ID_DESC with

    select LTRIM(ltrim(Accounts_ID) + '-' + ltrim(Accounts_Description)) as ID

    I don't know how to look up the description to do the parentID-Desc.

    Any help will be appreciated.

     

  • You might want to look at the following thread... http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=96968

     




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

  • Yes, you do need a self-join.  Something like this:

    SELECT LTRIM(a.ID) + '-' + a.Descr AS ID_Desc, LTRIM(b.ID) + '-' + b.Descr AS Parent_Desc

    FROM YourTableName a JOIN YourTableName b on b.ID = a.Parent_ID



    --Jonathan

  • Thanks to all for the replys.  I've got it.

     

    -Malcolm

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply