我需要返回一行:
.NET[tableReturn] = select top(1) * from [table] where x = 0 order by desc
但同时我需要更新它:
update [table] set x = 1 where [id] = .NET[tableReturn].[id]
并且需要这一行的所有数据
可以在同一个查询中吗?
我需要返回一行:
.NET[tableReturn] = select top(1) * from [table] where x = 0 order by desc
但同时我需要更新它:
update [table] set x = 1 where [id] = .NET[tableReturn].[id]
并且需要这一行的所有数据
可以在同一个查询中吗?
解决这个!
DECLARE @id int;
SET @id = (select top(1) id from [table] where [x] = 0 order by id desc);
select * from [table] where id = @id;
update [table] set [x] = 20 where id = @id;
:D
尝试这个
with cte as (select top(1) * from [table] where x=0 order by 1 desc)
update [table] set x=1 from cte join [table] c on c.id =cte.id;
使用存储过程。在存储过程中,您可以根据需要执行任意数量的查询。
没有它,您将不得不独立调用多个查询。
希望这可以帮助。
尝试以下查询以使用单个查询更新列。
update [table] set x = 1 where x = (select cte.x from (select top(1) * from [table] where x = 0 order by x desc) cte)
注意:-但更新的列不应该是标识列