declare @t_temp table(title int,product varchar(10)) insert @t_temp values(1 ,'a') insert @t_temp values(1 , 'b') insert @t_temp values(2 , 'a') insert @t_temp values(2 , 'c') insert @t_temp values(3 , 'c') insert @t_temp values(3 , 'd') insert @t_temp values(4 , 'd') insert @t_temp values(5, 'e') declare @你的参数 int set @你的参数=1declare @临时表 table(title int,product varchar(10))insert @临时表 select * from @t_temp where product in (select product from @t_temp where title=@你的参数)while exists(select 1 from @t_temp a where (product in (select product from @临时表) or title in (select title from @临时表)) and not exists (select 1 from @临时表 where title=a.title and product=a.product)) insert @临时表 select * from @t_temp a where (product in (select product from @临时表) or title in (select title from @临时表)) and not exists (select 1 from @临时表 where title=a.title and product=a.product)select * from @临时表
--邹建 2003.9--*/
insert @t_temp values(1 ,'a')
insert @t_temp values(1 , 'b')
insert @t_temp values(2 , 'a')
insert @t_temp values(2 , 'c')
insert @t_temp values(3 , 'c')
insert @t_temp values(3 , 'd')
insert @t_temp values(4 , 'd')
insert @t_temp values(5, 'e')
declare @你的参数 int
set @你的参数=1declare @临时表 table(title int,product varchar(10))insert @临时表 select * from @t_temp where product in (select product from @t_temp where title=@你的参数)while exists(select 1 from @t_temp a where (product in (select product from @临时表) or title in (select title from @临时表)) and not exists (select 1 from @临时表 where title=a.title and product=a.product))
insert @临时表 select * from @t_temp a where (product in (select product from @临时表) or title in (select title from @临时表)) and not exists (select 1 from @临时表 where title=a.title and product=a.product)select * from @临时表