欢迎投稿

今日深度:

SQL 在循环内修改字段值,sql循环修改字段

SQL 在循环内修改字段值,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

www.htsjk.Com true http://www.htsjk.com/shujukunews/8401.html NewsArticle SQL 在循环内修改字段值,sql循环修改字段 在网站找一段,发现并没有达到自己的要求: 这段程序功能是 为某空字段自动编号(系统运用时,新加的编号字段,前期有数据,需要重新编...
相关文章
    暂无相关文章
评论暂时关闭