0

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

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

1 回答 1

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

(未测试)

于 2012-10-23T07:32:54.683 回答