declare cur4 cursor for
select account_code
from acode
where account_code between @from_acct and @to_acct
and input_gbn = 'Y'
for read only
at isolation read uncommitted
select @yyyymm = max(yyyymm) from monthly_item_amt
where area_code in (select area_code from saso_code where
up_area = @area_code)
and sum_gbn = '1'
and yyyymm<substring(@from_yymm,1,6)
select @acct_date =
convert(datetime,substring(@yyyymm,1,4)+'/'+substring(@yyyymm,5,2)
+ '/01')
open cur4
fetch cur1 into @acct_code
while @@sqlstatus!=2 begin
select @acct_name=account_name,
@first_acct_code=first_account_code,
@acode_dc_code=dc_code
from acode
where account_code=@acct_code
at isolation read uncommitted
select @first_acct_name=account_name from acode
where account_code=@first_acct_code
at isolation read uncommitted
select @option_gbn=option_gbn from acode_mgt
where account_code=@acct_code and mgt_code='101'
at isolation read uncommitted
if @option_gbn = 'A'
declare cur2 cursor for
select mgt_item_code1, won_by_dr_amt+won_cy_dr_amt,
won_by_cr_amt+won_cy_cr_amt
from monthly_item_amt
where area_code in (select area_code from saso_code where
up_area=@area_code)
and account_code=@acct_code and sum_gbn='1'
and substring(mgt_item_code1,1,4) between
substring(@from_cust,1,4) and substring(@to_cust,1,4)
and yyyymm = @yyyymm
for read only
at isolation read uncommitted
if @option_gbn = 'B'
declare cur2 cursor for
select mgt_item_code2, won_by_dr_amt+won_cy_dr_amt,
won_by_cr_amt+won_cy_cr_amt
from monthly_item_amt
where area_code in (select area_code from saso_code where
up_area=@area_code)
and account_code=@acct_code and sum_gbn='1'
and substring(mgt_item_code2,1,4) between
substring(@from_cust,1,4) and substring(@to_cust,1,4)
and yyyymm = @yyyymm
for read only
at isolation read uncommitted
if @option_gbn = 'C'
declare cur2 cursor for
select mgt_item_code3, won_by_dr_amt+won_cy_dr_amt,
won_by_cr_amt+won_cy_cr_amt
from monthly_item_amt
where area_code in (select area_code from saso_code where
up_area=@area_code)
and account_code=@acct_code and sum_gbn='1'
and substring(mgt_item_code3,1,4) between
substring(@from_cust,1,4) and substring(@to_cust,1,4)
and yyyymm = @yyyymm
for read only
at isolation read uncommitted
open cur2
fetch cur2 into @cust_code, @debit_amt, @credit_amt
while @@sqlstatus!=2 begin
select @cust_code =max(custom_code)
from acustom
where substring(custom_code,1,4) = substring(@cust_code,1,4)
select @cust_name=custom_fname from acustom
where custom_code= @cust_code
at isolation read uncommitted
if @acode_dc_code = '1' begin
select @debit_amt = @debit_amt - @credit_amt
select @credit_amt = 0
select @remain_amt = @debit_amt - @credit_amt
end else begin
select @credit_amt = @credit_amt - @debit_amt
select @debit_amt = 0
select @remain_amt = @credit_amt - @debit_amt
end
if exists ( select * from #temp_cust_bojo
where slip_no = @jun
and acct_code = @acct_code
and substring(cust_code,1,4) =
substring(@cust_code,1,4))
update #temp_cust_bojo
set debit_amt = debit_amt + @debit_amt,
credit_amt = credit_amt + @credit_amt,
remain_amt = remain_amt + @remain_amt
where slip_no = @jun
and acct_code = @acct_code
and substring(cust_code,1,4) =
substring(@cust_code,1,4)
else
insert into #temp_cust_bojo(slip_no, acct_code,
acct_name, first_acct_code, first_acct_name,
acct_date, cust_code, cust_name,
dc_code, debit_amt, credit_amt, remain_amt, status)
values(@jun, @acct_code,
@acct_name, @first_acct_code, @first_acct_name,
@acct_date, @cust_code, @cust_name,
@acode_dc_code, @debit_amt, @credit_amt, @remain_amt,
'C')
fetch cur2 into @cust_code, @debit_amt, @credit_amt
end
close cur2
deallocate cursor cur2
fetch cur4 into @acct_code
end
close cur4
deallocate cursor cur4
-cur2를 open할 수 없다고 나오는군요
고수님들 댓글 감사합니다...
|