I am trying to create the correct structure of my sql (CTE) query, but I can not. This is a version I want to have .
And this is my current version: . As you can see there are duplicates and i have no idea how to get rid of them. Futhermore the structure is wrong. I already tried to look for solutions like here but was unable to come up with solution.
CTE query doesn't print the right structure?
My Employee table looks like this http://sqlfiddle.com/#!6/428d2/2
Here is my SQL query I use to create the correct name column: http://sqlfiddle.com/#!6/bf4c1/4
I use MsSQL 2012, so feel free to use newest fuctions etc. Any help appreciated.
Best Answer
If you specify the root node in the CTE, it works ok.
SQL Fiddle here.