如何使用sql by id(EmployeeID)中的hierarchyid类型变量的变量获取表中的父节点? 这是我的表
CREATE TABLE Employee
(
Node hierarchyid PRIMARY KEY CLUSTERED,
EmployeeID int UNIQUE NOT NULL,
EmpName varchar(20) NOT NULL,
Title varchar(20) NULL
) ;
GO
答案 0 :(得分:1)
我找到了解决问题的简单方法:
SELECT EmployeeID
FROM Employee
WHERE [Node] IN (
SELECT [Node].GetAncestor(1).ToString()
FROM Employee
WHERE EmployeeID=4
)
感谢您的回答!!!