注册 登录
编程论坛 SQL Server论坛

存储过程,请各位分析

jxawgya 发布于 2011-06-04 08:38, 418 次点击
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



--自动缴款

ALTER PROCEDURE  [dbo].[sp_mzsf_pay_jk]
 AS

DECLARE @opecode varchar(6),@billid varchar(12),@y int,@aa varchar(8)

set @aa = cast(year(getdate()) as varchar(4) )+ right('00'+cast(month(getdate()) as varchar(2)),2) + right('00'+cast(day(getdate()) as varchar(2)),2)
set @y = 0

declare  cur scroll cursor
for
select OPERATOR_CODE from ci_invoice
WHERE pay_date is null
group by OPERATOR_CODE
open cur

set @y =@y + 1
set @billid = @aa + right('0000'+cast(@y as varchar(4)),4)

fetch first from cur into @opecode
while ( @@fetch_status<>-1)
begin
insert into ci_invoice_pay(bill_id,invoice_sum,price_subclass)
select @billid,sum(invoice_sum),PRICE_SUBCLASS
from ci_invoice
where OPERATOR_CODE =@opecode and pay_flag = '0'  and CANCEL_SIGN = '1'  and  pay_date is null
group by price_subclass


fetch next from cur into @opecode

end
close cur
deallocate cur

update ci_invoice set pay_flag = '1' , pay_date =getdate()
where pay_date is null and pay_flag = '0'

update ci_withdraw_info set pay_flag = '1' , pay_date =getdate()
where pay_date is null and pay_flag = '0'

以上存储过程请各们分析,
1 回复
#2
panyanpan2011-06-09 09:01
请问下 要具体如何分析,还有表结构,对应实现的功能是什么
1