您好,欢迎访问一九零五行业门户网

动态交叉表-统计每天员工生日数

(2010-8-27 记录)动态交叉表-统计每天员工生日数: 1.表结构 emp ( id , empno,empname,gender,birthday,deptid ) dept(id,deptno,deptname) 2.要点: 2.1 每月天数,计算两个月初的日期差即可; 2.2 小计和合计,利用 group by with rollup 2.3 动态显
(2010-8-27 记录)动态交叉表-统计每天员工生日数:
1.表结构
emp ( id , empno,empname,gender,birthday,deptid )
dept(id,deptno,deptname)
2.要点:
2.1 每月天数,计算两个月初的日期差即可;
2.2 小计和合计,利用 group by with rollup
2.3 动态显示 1 号, 2 号, 3 号 …28 号, 29 号 … ,利用动态交叉表实现
3 .代码如下: 
/** 统计某月员工生日*/if exists (select * from sysobjects where id = object_id('sp_count_birthday') and objectproperty(id, n'isprocedure') = 1) drop procedure sp_count_birthdaygocreate procedure sp_count_birthday @p_month nvarchar(2) --月份with encryption asbegin begin transaction t1 declare @v_days int --当月天数 declare @v_first_day_m nvarchar(10) --当月第一天 declare @v_year nvarchar(4) --当前年份 declare @v_sql nvarchar(4000) --最后执行的sql declare @v_i int --计数 declare @v_total nvarchar(10) --合计 declare @v_subtotal nvarchar(10) --小计 set @v_total = n'合计' set @v_subtotal = n'小计' set @v_year = datepart(yyyy,getdate()) set @v_first_day_m = @v_year + '-' + @p_month + '-' + '01' set @v_days = datediff(dd,@v_first_day_m,dateadd(mm,1,@v_first_day_m)) create table #tmp_date(emp_birth datetime) set @v_i = 0 while(@v_i 0 begin rollback transaction t1 end else begin commit transaction t1 endendgo--exec sp_count_birthday '6'
其它类似信息

推荐信息