1,216
社区成员
发帖
与我相关
我的任务
分享
rs.Open "Select ID ERP_Code Document_No From Table order by ID asc" '先用此SQL 打开数据库 ,注意按ID升序排序.
if rs.recordcount>0 then '如果有数据进行以下操作
rs.MoveFirst '先移动至文件首行
bakData=rs.Fields("Document_No") '先将第一行的 Document_No 保存起来
rs.MoveNext '移动至下一条
while not rs.eof '如果未到文件尾
if len(rs.Fields("Document_No"))=0 then '如果记录是空的
rs.Fields("Document_No")= bakdata '等于上次保存后的值
else
bakData=rs.Fields("Document_No") '如果不为空,则保存最新值
end if
wend
end if
Create table #tmpA(ID int,ERP_Code varchar(100),Document_No varchar(100))
insert into #tmpA select 1,null,'100001943'
insert into #tmpA select 2,'2050000',null
insert into #tmpA select 3,'1111030',null
insert into #tmpA select 4,'5100200',null
insert into #tmpA select 5,'3456000','100001944'
insert into #tmpA select 6,'1300000',null
select * from #tmpA
Declare @ID int
,@maxID int
select @maxID=7
,@ID=1
while @ID<@maxID
Begin
update #tmpA set Document_No=
case when isnull(Document_No,'')=''
then
(select Document_No from #tmpA where ID=@ID-1 )
else
Document_No
end
where ID=@ID
select @ID=@ID+1
End
select * from #tmpA
drop table #tmpA