数据库

本类阅读TOP10

·SQL语句导入导出大全
·SQL Server日期计算
·SQL语句导入导出大全
·SQL to Excel 的应用
·Oracle中password file的作用及说明
·MS SQLServer OLEDB分布式事务无法启动的一般解决方案
·sqlserver2000数据库置疑的解决方法
·一个比较实用的大数据量分页存储过程
·如何在正运行 SQL Server 7.0 的服务器之间传输登录和密码
·SQL中两台服务器间使用连接服务器

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
福建公安高等专科学校贫困生补助处理T-SQl代码(含需求分析与设计)

作者:未知 来源:月光软件站 加入时间:2005-6-5 月光软件站

/* 福建公安高等专科学校贫困生补助处理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


相关文章

相关软件