重新整理
declare @定单 int,@显示顺序 int
select code,显示顺序,存储顺序 into #temp from 表 order by code,显示顺序update #temp set @显示顺序=case when code=@定单 then @显示顺序+100 else 1 end,@定单=code,显示顺序=@显示顺序
update 表 set 显示顺序=#temp.显示顺序 from #temp where #temp.code=表.code and #temp.存储顺序=表.存储顺序drop table #temp
declare @定单 int,@显示顺序 int
select code,显示顺序,存储顺序 into #temp from 表 order by code,显示顺序update #temp set @显示顺序=case when code=@定单 then @显示顺序+100 else 1 end,@定单=code,显示顺序=@显示顺序
update 表 set 显示顺序=#temp.显示顺序 from #temp where #temp.code=表.code and #temp.存储顺序=表.存储顺序drop table #temp
--------------------------------------------------------------------------------------------------------------------------------
select
TA001,
TA002,
round(TA015/(datediff(day,KPC02,KPC03)+1),3) as TA015,
dbo.split1(convert(char(8),KPC02,112),convert(char(8),KPC03,112)) as KPC02
from
MOCTA
where
rtrim(TA026)+rtrim(TA027)+rtrim(TA028)='22011011060183C0003'
and
TA011='1'