Sorting tree with other column in SQL Server 2008

Posted by bodziec on Stack Overflow See other posts from Stack Overflow or by bodziec
Published on 2010-04-26T08:10:03Z Indexed on 2010/04/26 8:13 UTC
Read the original article Hit count: 435

Filed under:
|
|

Hi,

I have a table which implements a tree using hierarchyid column

Sample data:

People             \
    Girls          \1\
        Zoey       \1\1\
        Kate       \1\2\
        Monica     \1\3\
    Boys           \2\
        Mark       \2\1\
        David      \2\2\

This is the order using hierarchyid column as sort column

I would like to sort data using hierarchyid but also using name so it would look like this:

People             \
    Boys           \2\
        David      \2\2\
        Mark       \2\1\        
    Girls          \1\
        Kate       \1\2\
        Monica     \1\3\
        Zoey       \1\1\    

Is there a simple solution to do this?

Czy da sie to zrobic w jednym zapytaniu sql ?

© Stack Overflow or respective owner

Related posts about sql-server-2008

Related posts about sql