試試這個
輸入
declare @tblA table (id int,name varchar(20))
declare @tblB table (id int,name varchar(20))
declare @tblC table (id int identity,name varchar(20))
insert into @tblC
select 'name1' union all select 'name2' union all
select 'name3' union all select 'name4' union all
select 'name5' union all select 'name6' union all
select 'name7' union all select 'name8' union all
select 'name9' union all select 'name10' union all
select 'name11' union all select 'name12' union all
select 'name13' union all select 'name14' union all
select 'name15' union all select 'name16' union all
select 'name17' union all select 'name18' union all
select 'name19' union all select 'name20'
查詢
insert @tblA
output INSERTED.id, INSERTED.Name
into @tblB
select
id,name
from @tblC
where id % 2 = 0
select * from @tblA
select * from @tblB
輸出: [對於這兩個表格中的& B]
ID名稱
2 name2
4 name4
6 name6
8 name8
10 name10
12 name12
14 name14
16 name16
18 name18
20 name20
基本上我將這些記錄到表A從表C,其ID是偶數。然後通過使用OUTPUT子句插入來自表A中的值表B
欲瞭解更多信息OUTPUT Clause
希望這是有道理
使用觸發器... – 2009-11-29 07:28:17
@邁克爾:爲什麼,當你可以運行在存儲過程中多個SQL語句? – 2009-11-29 07:39:39