日期:2014-05-18  浏览次数:20504 次

sql 循环插入数据问题
有table1 table2 
number strxxx number str 
1 aaa 1 a 
2 aaa 2 b 
3 aaa 3 c 
4 ccc 4 d 
5 ccc 5 e 

declare @number int,@string varchar(10) 
select @number = number from table1 where strxxx='aaa' 
select @str = str from table2 where number = @number 
insert into table3(number,str)values(@number,@str) 

我写的是触发器.. 

这样值只能插入一条数据 
我想把符合条件的都插入进去 
要怎么循环插入呢? 
很急...在线等........

------解决方案--------------------
SQL code

insert into table3(number,str) select '楼上'
insert into table3(number,str) 
select a.number,b.[str] from table1 a inner join table2 b  on a.number=b.number where strxxx='aaa'