UPDATE SELECT OUTPUT

-- 定义临时表变量,用于 output into 使用

DECLARE @VarOrderStatus table (
OrderNo nvarchar(50) NULL
)

 

-- update 表
UPDATE Order_Status
SET Order_Status.QueryTakeOut = 1,Order_Status.QueryCount = Order_Status.QueryCount+1


OUTPUT INSERTED.OrderNo -- output into
INTO @VarOrderStatus

 

-- select 表

FROM
(
SELECT TOP 10 * FROM Order_Status
WHERE Status=4 AND QueryTakeOut=0 AND QueryCount < 3
ORDER BY CreateTime DESC
) AS A

-- select.key = update.key
WHERE A.OrderNo = Order_Status.OrderNo

 

-- 查询临时表
SELECT * FROM @VarOrderStatus

posted @ 2018-04-16 13:57  黑手墨色  阅读(204)  评论(0编辑  收藏  举报