更新表行sql 3的列
在这张图片中,我想通过查询读取第一行,并将HASDATA更改为1或true(对于第一行),但所有行中的HASDATA都更改为true 我使用了这段代码,它可以工作,但是当这段代码在while环查询中运行时,仍然在同一行上工作。当代码在while环中运行时,我想在下一行中运行query 这是我的存储过程代码:更新表行sql 3的列,sql,sql-server,tsql,stored-procedures,sql-update,Sql,Sql Server,Tsql,Stored Procedures,Sql Update,在这张图片中,我想通过查询读取第一行,并将HASDATA更改为1或true(对于第一行),但所有行中的HASDATA都更改为true 我使用了这段代码,它可以工作,但是当这段代码在while环查询中运行时,仍然在同一行上工作。当代码在while环中运行时,我想在下一行中运行query 这是我的存储过程代码: ALTER procedure [dbo].[selecfirstvalue] (@ParentId int,@CrawlerCheck bigint) as update TBLCrowl
ALTER procedure [dbo].[selecfirstvalue] (@ParentId int,@CrawlerCheck bigint)
as
update TBLCrowler set ParentId=@ParentId , CrawlerCheck=@CrawlerCheck , HasData=1
where CatId=(Select min(CatId) from TBLCrowler)
end
试试这个:
ALTER procedure [dbo].[selecfirstvalue] (@ParentId int,@CrawlerCheck bigint)
as
update TBLCrowler set ParentId=@ParentId , CrawlerCheck=@CrawlerCheck , HasData=1
where CatId=(Select min(CatId) from TBLCrowler where HasData=0)
end
where子句将始终拾取相同的记录,即CatId最低的记录