将一张表中的部分记录插入到另一张表中

 1 create table  #a 
 2 (
 3    ID INT,
 4    CODE varchar(100),
 5    Name varchar(100),
 6 )
 7 
 8 insert #a 
 9 select 1,'a','扬子江'
10 union all
11 select 2,'a','扬子江'
12 union all
13 select 3,'a','扬子江'
14 union all
15 select 3,'a','黄浦江'
16 union all
17 select 3,'a','澜沧江江'
18 
19 select * from #a 
20 
21 
22 create table  #b
23 (
24    ID INT,
25    CODE varchar(100),
26    Name varchar(100),
27 )
28 insert into #b(ID,CODE,Name) select ID,'b',Name from #a where Name='扬子江'
29 
30 select * from  #b
View Code

原文地址:https://www.cnblogs.com/hshuai/p/4310690.html