I have a CTE Recursive query which returns the output as expected, however It would be nice if I can control the sort. For example I would like to sort PARENT nodes by using a custom SORT column in table…and IF POSSIBLE sort the nodes under Parent Categories as well by using a SORT column.
Hete is SQL Fiddle
Please look at sort Column, With Sort output should be something like this.
Appliances < -- Parent
Dryers
Washers
Toys < -- Parent
Furniture < -- Parent
if sorting on child nodes is NOT possible then its fine, but it would be nice to atleast control the sort for PARENT nodes.
EDIT
Try this for the latest question/fiddle edit. Same idea, but one more ISNULL, as I forgot to handle NULL sorts in the recursive part.
Note: A single varchar(max) within a series of string concatenations makes the end result a varchar(max). A single cast will do.
FYI – for future SQL questions, it would be really great if you could prepare a SQLFiddle schema, and what query you have thus far. This allows others to spend minimal time on setup. It also helps the discussion if you had to expand on the sample or provide what if query variants.