一、標題的情況其實是不可以的。但可以用另一種方式解決
CREATE FUNCTION test(@ID_Department bigint) RETURNS TABLE AS RETURN ( select id,DepartmentName from SysDepartment where id=@ID_Department) GO
調用 :
select * from test(16508640061124406)
二、
with tmpTable as ( -- 1、根節點 select * from myTableName where Id = 16508640061124406 union all -- 2、遞歸條件 select a.* from myTableName a inner join tmpTable b on a.parentId= b.id ) select * from tmpTable;