日期:2014-05-18 浏览次数:20659 次
insert into c select b.no,a.id,3 from a corss join b where b.rty = 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
------解决方案--------------------
--> 测试数据: @表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
*/