/* total count for the query result */
declare @totalcount int
declare @rownum int
select @totalcount = (select count(1) from Table)
set @rownum = 1
while @rownum <= @totalcount
begin
declare @num int
declare @id decimal(18,0)
select @id=ID from (select ROW_NUMBER() over(order by id) as rows,ID from Table) U where rows =@rownum
set @num=(select distinct len(replace(name,'-','--'))-len(name) from Table WHERE ID=@id)
IF(@num>=3)
SET @num=3
update Table set CengJi = @num where [id] = @id
set @rownum = @rownum + 1
end
GO
SQL循环更字段的值
最新推荐文章于 2024-11-23 22:57:02 发布