SQL循环更字段的值

来源:互联网 发布:Laymine java 编辑:程序博客网 时间:2024/06/10 01:42
  /* total count for the query result */declare @totalcount intdeclare @rownum intselect @totalcount = (select count(1) from Table)set @rownum = 1while @rownum <= @totalcount    begindeclare @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

0 0
原创粉丝点击