将Select语句转换为Update语句

时间:2013-12-06 17:39:36

标签: sql sql-server sql-server-2012

我正在使用此查询从6个结果中提取某一行(2),但我想从6个数据结果对第(2)行的标题运行更新查询。

我必须使用UNION吗?我不知道如何编写查询。

with cte as
(
    Select Title, Title_Row = ROW_NUMBER() OVER (ORDER BY ID ASC)
    From products.features
    where productid = '172'
)
select Title
from cte
where Title_Row = 2

感谢

1 个答案:

答案 0 :(得分:2)

;with cte as
(
    Select Title, Title_Row = ROW_NUMBER() OVER (ORDER BY ID ASC)
    From products.features
    where productid = '172'
)
UPDATE CTE
SET Title = ??? --<-- Your new value
where Title_Row = 2