过滤输出子句sql

时间:2011-07-12 06:23:11

标签: sql-server tsql

我正在尝试对t-sql中的OUTPUT子句使用过滤器。

我想做的是这样的事情:

Insert into tbl_1(col1,col2)
Output Inserted.col1 into #tbl_temp 
**where col1 > 0**
select col3, col4
from tbl_2

出于性能原因,我不想使用两个插入语句。

1 个答案:

答案 0 :(得分:7)

insert into #tbl_temp
select col1
from
  (
    insert into tbl_1(col1,col2) 
    output Inserted.col1
    select col3, col4 
    from tbl_2
  ) as T
where T.col1 > 0