0

我有两个这样的临时表:

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

怎么做?

4

1 回答 1

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
于 2012-05-17T07:35:24.777 回答