From Up to Low hierarchy

  • Hello!

    Problem is to sort from High to Low or from Up to Down!

    Have table like this:

    CREATE TABLE #PUC

    (

    CODE CHAR(3),

    POSITION VARCHAR(30),

    GRADE INT

    )

    INSERT INTO #PUC

    SELECT '100', 'ABOSS', 10 UNION ALL

    SELECT '101', 'A1', 9 UNION ALL

    SELECT '102', 'A2', 8 UNION ALL

    SELECT '200', 'BBOSS', 10 UNION ALL

    SELECT '201', 'B1', 9 UNION ALL

    SELECT '202', 'B2', 8

    And I want to see my results like this

    CODE |POSITION |Grade| Hierarchy

    100ABOSS10 -

    101A1 9 ABOSS

    102A2 8 ABOSS - A1

    200BBOSS10 -

    201B1 9 BBOSS

    202B2 8 BBOSS - B1

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • Hi,

    I am struggling to understand your example so perhaps you could qualify it a little further please.

    What relates (ABOSS) to (A1) in order to create (ABOSS - A1)? Does the code denote the hierarchy?

    Cheers,

  • ABOSS is BOSS of A department

    A1 is Team Leader of department A

    A2 is employee

    So

    A Boss

    A1 Team Leader

    A2 Employee

    The hierarchy is BOSS >>> BOSS-TeamLeader >>> BOSS-TeamLeader-Employee

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

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

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