/* 福建公安高等专科学校贫困生补助处理T_SQl代码 需求分析与设计
*贫困生补助:1、部份贫困生原已有学校给予的常规补助(称为A型卡),但卡类别不一致(发补助时以卡类别为标准),且这些卡类中的卡中只有部分是贫困生卡。
2、现要求为A型卡的贫困生实际补助额为在原有常规补助额上增加贫困补助额。
3、增加没有常规补助的贫困生(称为B型卡)的补助记录(要非0类卡,否则天王老子都没办法,0类卡不能领补助),其实际补助额就为贫困补助额。
4、补助月报要有所体现(主要在当月计划补助金额上)。
*前提条件:1、一张卡补助一个月只能领一次(补助以月为发放单位)。2、公安专只能提供含有姓名、部门、贫困补助额等列值的名单,可能含有同名同姓的但没有贫困补助的学生!
*方案:1、采取相关的信息在当月补助形成后发放前修正,以保证在不动卡内信息的基础上实现常规补助和贫困补助的正常发放。 2、 新建两个基本表:CREATE
TABLE [customerid] ( [customerid] [int] NOT NULL ,--客户号 [pk_subsidyfare] [money]
NOT NULL ),--贫困补助额 CREATE TABLE [name] ( [name] [varchar] (12) COLLATE
Chinese_PRC_CI_AS NOT NULL ,--姓名 [pk_subsidyfare] [money] NOT NULL ) --贫困补助额
3、提取公安专提供的贫困补助名单中的姓名、贫困补助额列值信息(Excel形式)导入到name表中去。在name表基础上新建一个含有customerid、name、部门、pk_subsidyfare列值信息的视图。
4、把含有customerid、name、部门、pk_subsidyfare列值的信息的视图导出到Excel中去,作为同名同姓学生筛选排除之用。
5、把以上筛选排除的结果中的customerid、pk_subsidyfare列值的信息导入到customerid表中去!
6、执行以下的代码(注意只能执行一次,否则实际补助额将会多出、补助月报当月计划补助金额会超支,确记!!) */ declare
@pk_count/*作贫困生补助记录数统计之用*/ int,@pk_sum_subsidyfare/*作补助额统计之用*/
money,@customerid/*客户号*/ int,@pk_subsidyfare/*贫困补助额*/ money,@subsidyfare/*补助额*/
money,@k/*卡类*/ int,@month/*月份*/ datetime, @subsidyfare1/*补助额*/ money select
@month= month from t_subsidymonthplan/*获取补助当月份值*/ declare pk_cursor cursor for
select customerid,pk_subsidyfare from customerid/*定义贫困生游标,从customerid表查询获取*/
open pk_cursor fetch next from pk_cursor into @customerid,@pk_subsidyfare while
(@@fetch_status=0)/*更改、处理t_customers、t_subsidymonthplan、t_subsidypre表相关明细记录的循环*/
begin select @k=cardtype from t_customers where customerid=@customerid select
@subsidyfare=cursubsidyfare from t_customers where
customerid=@customerid/*获取贫困生当月常规补助额*/ select @subsidyfare1=subsidy from
t_subsidymonthplan where customerid=@customerid set
@subsidyfare=@subsidyfare+@pk_subsidyfare/*贫困生实际补助额=常规补助额+贫困补助额*/ set
@subsidyfare1=@subsidyfare1+@pk_subsidyfare if not exists(select * from
t_subsidymonthplan where customerid=@customerid) begin/*B型卡处理代码段*/ update
t_customers set
cursubsidyfare=@subsidyfare,subsidydt=@month,subsidyout=''''F'''' where
customerid=@customerid insert into t_subsidymonthplan
values(@month,@customerid,@k,@subsidyfare1) insert into t_subsidypre
values(@month,@customerid,@k,@subsidyfare1) end else begin/*A型卡处理代码段*/ update
t_customers set cursubsidyfare=@subsidyfare where
customerid=@customerid/*更改T_customers表中贫困生记录的cursubsidyfare字段指*/ update
t_subsidymonthplan set subsidy=@subsidyfare1 where
customerid=@customerid/*更改T_subsidymonthplan表中贫困生记录的subsidy字段指*/ update
t_subsidypre set subsidy=@subsidyfare1 where customerid=@customerid and
month=@month/*更改T_subsidypre表中贫困生当月记录的subsidy字段指*/ end fetch next from pk_cursor
into @customerid,@pk_subsidyfare end close pk_cursor deallocate pk_cursor set
@k=1/*卡类初设*/ while (@k<=15)/*处理t_subsidymonth表的相关汇总信息的循环*/ begin if
exists(select * from t_subsidymonth where cardtype=@k and
month=@month)/*判断某一类卡在t_subsidymonthplan表是否有记录*/ begin/*处理A型卡或有补助要补发的某一类卡的代码段*/
select @pk_count=count(*),@pk_sum_subsidyfare=isnull(sum(subsidy),0) from
t_subsidymonthplan where cardtype=@k update t_subsidymonth set
plancount=@pk_count,plansubsidy=@pk_sum_subsidyfare where month=@month and
cardtype=@k end else begin/*处理B型卡的代码段*/ if exists(select * from
t_subsidymonthplan where cardtype=@k) begin select
@pk_count=count(*),@pk_sum_subsidyfare=isnull(sum(subsidy),0) from
t_subsidymonthplan where cardtype=@k insert into t_subsidymonth
values(@month,@k,@pk_count,@pk_sum_subsidyfare,0,0,0,0,0,0,0,0,0,0,0,getdate(),getdate(),0)
end end set @k=@k+1 end
[C语言系列]C# DataSet String Byte[] 压缩 解压缩 代码 实例 [C语言系列]c#获取真实IP和代理IP代码 [C语言系列]c# 判断网络是否连接代码 [C语言系列]c#模拟鼠标键盘操作代码详解 [网页制作]js图片无缝滚动代码集锦 [Web开发]一段ASP防采集的代码,让小偷程序无处可采 [Web开发]supersite7.5首页模板代码收藏 [互联动态]网页防复制代码 [Web开发]浮动窗口代码,飘浮窗口代码 [网页制作]网页自动跳转代码大集合[站长常用代码集合]