加入输出结果

时间:2012-10-23 06:58:48

标签: sql-server tsql

为什么这个查询无法运行?

select * 
from ass 
join (
    UPDATE [dsa]
    SET col1='123'
    OUTPUT inserted.*) as ds on ass.dsaid = ds.ID

1 个答案:

答案 0 :(得分:1)

你必须分两步完成。使用OUTPUT子句转到变量,然后从该变量中选择:

DECLARE @tbl_out TABLE(ID int, col VARCHAR(10));

UPDATE [dsa] SET [col1] = '123'
OUTPUT inserted.* INTO @tbl_out

SELECT * FROM ass JOIN @tbl_out ds ON ass.dsaid = ds.ID

(未经测试)