use ufdata_帐套号_2008
Declare @cCode nvarchar(15)
Declare @iMaxMonth Int
select中distinctDeclare @iCount Int
Declare AccSumCur CURSOR For
Select Distinct cCode From (Select cCode,Count(*) as CountNum From GL_AccSum Group By cCode) A Where A.CountNum <> 12
Open AccSumCur
FETCH NEXT FROM AccSumCur
INTO @cCode
WHILE @@FETCH_STATUS = 0
BEGIN
--取得每个科目在GL_AccSum表中存在纪录的最大月份
Set @iMaxMonth = (Select Max(iPeriod) From GL_AccSum Where cCode = @cCode)
Set @iCount = @iMaxMonth + 1
While @iCount < 13
Begin
If (@iCount = @iMaxMonth + 1)--第一个缺少的月,将上个月的期末信息当成这个月的期初
INSERT INTO [GL_AccSum]([ccode],[cexch_name],[iperiod],[cbegind_c],[cbegind_c_engl],[mb],[md],[mc],[cendd_c],[cendd_c_engl],[me],[mb_f],[md_f],[mc_f],[me_f],[nb_s],[nd_s],[nc_s],[ne_s])
Select cCode,cexch_Name,@iMaxMonth + 1,cendd_c,cendd_c_engl,me,0,0,cendd_c,cendd_c_engl,me,me_f,0,0,me_f,ne_s,0,0,ne_s From GL_AccSum Where cCode = @cCode And iPeriod = @iMaxMonth
Else--不是第一个缺少的月,则将上个月的信息复制到这个月
INSERT INTO [GL_AccSum]([ccode],[cexch_name],[iperiod],[cbegind_c],[cbegind_c_engl],[mb],[md],[mc],[cendd_c],[cendd_c_engl],[me],[mb_f],[md_f],[mc_f],[me_f],[nb_s],[nd_s],[nc_s],[ne_s])
Select cCode,cexch_Name,@iCount,cbegind_c,cbegind_c_engl,mb,0,0,cendd_c,cendd_c_engl,me,mb_f,0,0,me_f,nb_s,0,0,ne_s From GL_AccSum Where cCode = @cCode And iPeriod = @iMaxMonth+1
Set @iCount = @iCount + 1
End
FETCH NEXT FROM AccSumCur
INTO @cCode
END
CLOSE AccSumCur
DEALLOCATE AccSumCur

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。