Cyclic processing--sqlserver

Source: Internet
Author: User

Alter PROCEDURE [dbo]. [Sp_gongzi] @gongzi_yf varchar (7) AS
DECLARE @input_id varchar (20)
DECLARE @sk_sum Decimal (18, 3)
DECLARE @sk_sum_yk Decimal (18, 3)
BEGIN
DECLARE Cur_input CURSOR for
Select Docno from tc_tab1 where YF = @gongzi_yf

OPEN Cur_input

FETCH Cur_input into @input_id
While @ @FETCH_STATUS = 0
BEGIN
Set @sk_sum = 0
Set @sk_sum_yk = 0
Select @sk_sum = SUM (JE * case when (HL2 was null) then HL else HL2 end)
From Sk_dan where docno[email protected]_id;

Select @sk_sum_yk = SUM (JE * case when (HL2 was null) then HL else HL2 end)
From Sk_dan_yk where docno[email protected]_id;

Set @sk_sum = case when (@sk_sum was null) then 0 else @sk_sum end;
Set @sk_sum_yk = case when (@sk_sum_yk was null) then 0 else @sk_sum_yk end;

Update TC_TAB1 Set dke2 = @sk_sum + @sk_sum_yk
where docno = @input_id;

FETCH Cur_input into @input_id
END
CLOSE Cur_input
Deallocate cur_input
--*/
END

Cyclic processing--sqlserver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.