福建公安高等专科学校贫困生补助处理T-SQl代码(含需求分析与设计)

类别:数据库 点击:0 评论:0 推荐:
/* 福建公安高等专科学校贫困生补助处理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

本文地址:http://com.8s8s.com/it/it19026.htm