在t-sql中将tableB的所有行添加到tableA的所有行
问题描述:
我有两个表,并且需要将表B的所有行添加到表A的所有行,请注意两个表中的行数不是静态的但会动态增加或减少,请提出建议。下面的屏幕截图可以清楚地说明。 enter image description here在t-sql中将tableB的所有行添加到tableA的所有行
答
希望您正在寻找交叉通过加入与为了沿着 SQL功能。
Declare @table1 table (id int,employee nvarchar(max),Month0 nvarchar(max))
Declare @table2 table (Month0 nvarchar(max))
insert into @table1
values(1,'rick',null)
insert into @table1
values(2,'tom',null)
insert into @table1
values(3,'John',null)
insert into @table2
values('Jan')
insert into @table2
values('Feb')
insert into @table2
values('Mar')
select * from @table1
select * from @table2
select id,employee,b.Month0 from @table1 as a cross join @table2 as b order by id
感谢您的快速回复,结果集是所有我需要的,但我需要表1(在上面的例子),结果通过消除所有空值更新,请建议如何实现这一点。 – ArK
你没有提到关于更新table1的任何内容,或者说你的问题与你在评论 –
中提到的要求不太清楚,请查看SQL中的CRUD操作,JOINS,dbms中的规范化, –