我有两个像这样的临时表:
declare @Tbl_A table
(
Id int
)
declare @Tbl_b table
(
Seat nchar(1)
)
示例数据:
Tbl_A Tbl_B
10 A
11 B
12 C
我想根据第一个和第二个临时表将该数据插入到表Tbl_C
中:
Tbl_C
(
Id int,
Seat nchar(1)
)
结果数据:
Id Seat
10 A
10 B
10 C
11 A
11 B
11 C
怎么做?
答案 0 :(得分:3)
您需要执行CROSS JOIN
:
INSERT INTO Tbl_C
SELECT Id, Seat FROM @Tbl_A CROSS JOIN @Tbl_B
SELECT * FROM Tbl_C ORDER BY Id, Seat