方法一:
DECLARE @employeeid INT; set @employeeid = 8115; DECLARE @id INT; DECLARE @pid int; DECLARE @level int; SET @id=-1 --获取父节点id SELECT @id = RecID, @pid = PID, @level = [Level] FROM Organization.dbo.OfficePlace WHERE recid= (SELECT TOP 1 OfficePlaceID FROM Organization.dbo.Employees WHERE EmployeeId=@employeeid) WHILE (@pid!=-1) BEGIN SELECT @id = RecID,@pid = PID,@level = [Level] FROM Organization.dbo.OfficePlace where status=0 AND RecID=@pid END PRINT @id DECLARE @employeeid INT; set @employ