假设父项字段是Parent,子项字段是son,临时表为T3Create Function FindParent ( @Item varchar(50) ) Returns varchar(50)AS Begin Declare @Parent varchar(50) Set @Parent=@Item While (@Parent is not null) Begin Select @Parent =Parent From T3 Where Son = @Parent if @@rowcount=0 Return @Parent End Return @ParentEnd 用以下语句来查询物料E的顶层父项select dbo.FindParent('E')