有这样一个应用:
原始表table1中有个字段qty,sum后大于10000,现在要求不破坏每条记录的值,把table1的记录一条一条抄写到一个结构一样的新表table2中,要求插到table2的sum(qty)>5000时,就停止插入,怎么写这个存储过程,应该要用到游标吧?
原始表table1中有个字段qty,sum后大于10000,现在要求不破坏每条记录的值,把table1的记录一条一条抄写到一个结构一样的新表table2中,要求插到table2的sum(qty)>5000时,就停止插入,怎么写这个存储过程,应该要用到游标吧?
into #t from table1insert table2(...)
select ... from #t a
where (select sum(qty) from #t where id<=a.id)<=5000drop table #t
into #t from table1insert table2(...)
select ... from #t a
where (select sum(qty) from #t where id<a.id)<=5000drop table #t
into #t from table1delete a from # a
where (select sum(qty) from #t where id>=a.id)>5000alter table # drop idnew
goinsert table2 select * from #
drop table #
delete a from # a
where (select sum(qty) from #t where id>=a.id)>5000
怎么理解,哪位能否解释一下
where (select sum(qty) from #t where id=a.id)>5000