SQL Server 2005 recursive query with loops in data - is it possible?

前端 未结 10 1824
野趣味
野趣味 2020-12-06 03:29

I\'ve got a standard boss/subordinate employee table. I need to select a boss (specified by ID) and all his subordinates (and their subrodinates, etc). Unfortunately the rea

10条回答
  •  遥遥无期
    2020-12-06 04:07

    Not a generic solution, but might work for your case: in your select query modify this:

    select a.[User_ID], a.[Manager_ID] from [User] a join UserTbl b on (a.[Manager_ID]=b.[User_ID])
    

    to become:

    select a.[User_ID], a.[Manager_ID] from [User] a join UserTbl b on (a.[Manager_ID]=b.[User_ID]) 
       and a.[User_ID] <> @UserID
    

提交回复
热议问题