• peterausger (8/29/2014)


    this is what i tried and not getting the expected op

    ;WITH SInfo AS

    (

    SELECTsId

    ,scode

    ,ParentId

    ,sName

    ,CONVERT(nvarchar(800), scode) AS Hierarchy

    FROMtest

    WHEREParentId=0

    UNIONALL

    SELECTTH.sId

    ,TH.scode

    ,TH.ParentId

    ,TH.sName

    ,CONVERT(nvarchar(800), (SInfo.Hierarchy +'\' + CONVERT(nvarchar(800), TH.scode)))

    FROMtest TH

    INNER JOINSInfoONSInfo.sId = TH.ParentId

    )

    Select * from SInfo

    thanks

    peter

    Peter,

    Post the data and the table as recommended in the first link under "helpful" links in my signature line below and I'm sure that someone will be able to answer your question in two shakes.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)