34,837
社区成员




这样???
select * from a where exists(select * from dbo.udf_b(a.userid))
create table tb(flid int, flmc varchar(16), pid int)
insert tb select 1, '电影', 0
union all select 2, '国产', 1
union all select 3, '大陆', 2
union all select 4, '南宁', 3
union all select 5, '桂林', 3
union all select 6, '连续剧', 1
go
create function fn_GetParents(@ID int)
returns @tb table(flid int, flmc varchar(16), pid int) as
begin
select @ID=pid from tb where flid=@ID
while @ID<>0
begin
insert @tb select * from tb where flid=@ID
select @ID=pid from tb where flid=@ID
end
return
end
go
declare @ID int, @pID int
set @ID=4
select * from dbo.fn_GetParents(@ID)
order by flid
--这一句与你的类似,执行结果正常,不存在语法错误
select * from tb
where exists (select * from dbo.fn_GetParents(tb.flid))
/*
flid flmc pid
----------- ---------------- -----------
1 电影 0
2 国产 1
3 大陆 2
(3 row(s) affected)
flid flmc pid
----------- ---------------- -----------
2 国产 1
3 大陆 2
4 南宁 3
5 桂林 3
6 连续剧 1
(5 row(s) affected)
*/
drop function dbo.fn_GetParents
drop table tb