设为首页 加入收藏

TOP

SQL在循环内修改字段值
2015-11-21 01:52:11 来源: 作者: 【 】 浏览:0
Tags:SQL 循环 修改 段值

在网站找一段,发现并没有达到自己的要求:

这段程序功能是 为某空字段自动编号(系统运用时,新加的编号字段,前期有数据,需要重新编号)

declare @id int

declare @maxid int
set @id=1
select @maxid=count(*) from t_Send_Revisit Where fSO is null
begin
while @id<=@maxid
begin
update s set fSO =(Select 'SR' +CONVERT(varchar(100), GETDATE(), 112)+ '-' +RIGHT('0000'+convert(varchar,@id),4)) from t_Send_Revisit s
inner join (select top 1 * From t_Send_Revisit Where fSO is null ) t on t.SSO=s.SSO and t.STime = s.STime and t.fSNo= s.fSNo and s.CustCode = t.CustCode
set @id=@id+1
end
end

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇awrrpt.sql 下一篇Mongodb-使用C#Drivers实现增删改..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: