Home Forums SQL Server 2008 T-SQL (SS2K8) Hierarchy example - Ken Henderson's book - not working RE: Hierarchy example - Ken Henderson's book - not working

  • There's a problem in the SELECT statement in the WHILE. In the JOIN, there's only one record where ( o1.employee = o2.supervisor ) and it is excluded by the WHERE clause. Can you check the query in the book one more time?

    SELECT DISTINCT

    o1.chartdepth + 1 ,

    o1.employee ,

    o1.supervisor

    FROM

    #org_chart o1

    JOIN

    #org_chart o2

    ON ( o1.employee = o2.supervisor )

    WHERE

    o1.chartdepth = (

    SELECT

    MAX(#org_chart.chartdepth)

    FROM

    #org_chart

    )

    AND

    o1.supervisor <> o1.employee