question

giri00004 avatar image
giri00004 asked

how to get emp hierchy with out using cte in sql?

employee_id manager_id 1 1 2 1 3 1 4 2 5 1 6 3 7 2 8 2 9 3 10 2 How to get the emanager's subordinates and their levels with out using cte. because we have to impliment the same in my sql oup put like this @Managerid = 1 manager_id employee_id Level 1 2 1 1 3 1 1 5 1 2 4 2 2 7 2 2 8 2 2 10 2 3 9 3 level 1 is direct reporting to the variable suplied manager leve2 and 3...so on are indirect reporting to the ariable suplied manager's reporting employee(also manager for other employees)
sqlmssqlmsbi
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
I'd suggest looking at the MySQL answer on this similar question here : http://stackoverflow.com/questions/5291054/generating-depth-based-tree-from-hierarchical-data-in-mysql-no-ctes But why not use a CTE in SQL Server? Are you trying to write truly portable code?
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.