CREATE proc usp_ins_requisite_sc @bill char(16),@stateman varchar(50)
as
begin
declare @rowno char(8),
@row_id char(8),
@bombill varchar(50)
declare temp_cursor cursor for
select distinct(y.bombill),isnull(y.row_id,''),isnull(y.rowno,'') from vw_salebill x,t_bombill y
where x.bill=@bill and x.itemcode=substring(y.fatherbill,1,10) and y.workname is not null and y.itemcode like '7%' and y.workname not in ('06','01') and isnull(y.type,'1') <> '0'
open temp_cursor
fetch next from temp_cursor into @bombill,@row_id,@rowno
-- while @@fetch_status = 0
begin
-- select @fatherbill = x.itemcode from vw_salebill x,t_bombill y
-- where x.bill=@bill and x.itemcode=y.fatherbill and y.itemtype='1'
if @row_id = ''
begin
insert into t_requisite_sc
(salebill,orderbill,custcode,custname,rundate,senddate,
prodcode,oldprodcode,prodname,prodmodel,
prodstandards,prodnum,wdep,odep,cdep,
fnum,sfanum,prepnum,itemcode,oldcode,
itemnum,workstep,applynum,plannum,type,state,billman,billdate,remark,cremark,bomunit,bomnum,color,cloth,wstuff,gild,workname,stuff,outdate,unitcode)
select
x.bill+x.rowno,x.orderbill,x.cust_code,x.cust_name,x.statedate,x.senddate1,
x.itemcode,x.oldcode,x.itemname,x.itemmodel,
x.standards,x.itemnum,x.wdep,x.odep,x.cdep,
x.fnum,x.sfanum,x.prepnum,y.itemid,y.itemcode,
x.itemnum*y.itemnum,y.workstep,x.itemnum*y.itemnum,0,'1','0',@stateman,getdate(),x.remark,dbo.uf_getcremark(itemid) ,
y.bomunit,y.bomnum,dbo.uf_getcolor(y.itemid),dbo.uf_getcloth(y.itemid),x.wstuff,x.gild,
CASE y.workname WHEN '04' THEN 'D021' WHEN '05' THEN 'D022' WHEN '06' THEN 'D017' WHEN '16' THEN 'D018' WHEN '18' THEN 'D019' WHEN '20' THEN 'D020' WHEN '25' THEN 'D043' WHEN '30' THEN 'D024' WHEN '01' THEN '0000' WHEN '54' THEN 'D054' WHEN '55' THEN 'D055' WHEN '56' THEN 'D056' WHEN '57' THEN 'D057' end,stuff,outdate,y.unitcode
from vw_salebill x,t_bombill y
where x.bill=@bill
and x.itemcode=substring(y.fatherbill,1,10) and y.workname is not null and y.itemcode like '7%' and y.workname not in ('06') and isnull(y.type,'1') <> '0'
-- and substring(bombill,1,13) in (select y.bombill from vw_salebill x,t_bombill y where x.bill=@bill and substring(y.fatherbill,1,10) like x.itemcode and produce_type='2' and y.itemcode like '7%' )
end
if @rowno = ''
begin
insert into t_requisite_sc
(salebill,orderbill,custcode,custname,rundate,senddate,
prodcode,oldprodcode,prodname,prodmodel,
prodstandards,prodnum,wdep,odep,cdep,
fnum,sfanum,prepnum,itemcode,oldcode,
itemnum,workstep,applynum,plannum,type,state,billman,billdate,remark,cremark,bomunit,bomnum,color,cloth,wstuff,gild,workname,stuff,outdate,unitcode)
select
x.bill+x.rowno,x.orderbill,x.cust_code,x.cust_name,x.statedate,x.senddate1,
x.itemcode,x.oldcode,x.itemname,x.itemmodel,
x.standards,x.itemnum,x.wdep,x.odep,x.cdep,
x.fnum,x.sfanum,x.prepnum,y.itemid,y.itemcode,
x.itemnum*y.itemnum,y.workstep,x.itemnum*y.itemnum,0,'1','0',@stateman,getdate(),x.remark,dbo.uf_getcremark(itemid) ,
y.bomunit,y.bomnum,dbo.uf_getcolor_p(y.itemid),dbo.uf_getcloth(y.itemid),x.wstuff,x.gild,
CASE y.workname WHEN '04' THEN 'D021' WHEN '05' THEN 'D022' WHEN '06' THEN 'D017' WHEN '16' THEN 'D018' WHEN '18' THEN 'D019' WHEN '20' THEN 'D020' WHEN '25' THEN 'D043' WHEN '30' THEN 'D024' WHEN '01'
THEN '0000' WHEN '54' THEN 'D054' WHEN '55' THEN 'D055' WHEN '56' THEN 'D056' WHEN '57' THEN 'D057' end,stuff,outdate,y.unitcode
from vw_salebill x,t_bombill y
where x.bill=@bill
and x.itemcode=substring(y.fatherbill,1,10) and y.workname is not null and y.itemcode like '7%' and y.workname not in ('06') and isnull(y.type,'1') <> '0'-- and produce_type<>'2'
-- and substring(bombill,1,13) in (select y.bombill from vw_salebill x,t_bombill y where x.bill=@bill and substring(y.fatherbill,1,10) like x.itemcode and produce_type='2' and y.itemcode like '7%' )
end
fetch next from temp_cursor into @bombill,@row_id,@rowno
end
close temp_cursor
deallocate temp_cursor
end
祖传存储过程,mssql2000,这玩意游标实际查询的时候90条以上的数据,@row_id全部为null,@rowno全部不为null,但是游标实际只执行了一次,是不是我哪里看漏了,不然90条的记录游标只循环一次我无法理解啊。