22,210
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据: @表A
declare @表A table (col int)
insert into @表A
select 10001 union all
select 10002
declare @表B table (NO int,ACTI varchar(1))
insert into @表B
select 980001,'Y' union all
select 980002,'Y' union all
select 980003,'N'
select col,NO,3 as ACTI from @表A a cross join @表B b where b.ACTI='Y'
/*
col NO ACTI
----------- ----------- -----------
10001 980001 3
10001 980002 3
10002 980001 3
10002 980002 3
*/
insert into c
select a.id,b.no,3
from (select distinct id from a) a
join (select distinct no from b where ACTI='Y') b
on 1=1
insert into c
select b.no,a.id,3
from a corss join b
where b.rty = 3