最近写了一个人数统计的系统,要求是列及行都是动态生成的
比如:
数据库里面有个基础表A: 表A 姓名 部门 学历 出生年月
A 后勤 高中 1986-1-1
B 后勤 初中 1984-3-7
C 管理 本科 1987-2-1
D 操作 专科 1976-2-1
. . . .
. . . .
要求动态的生成一下效果的表:
部门 年龄段 高中 初中 本科.......
后勤 20-30 3 4 3 .......
30-40 3 9 0 .......
40-50 0 30 3 .......
管理 20-30 9 2 2 ....... 存储过程我已经写完了,在sql里面执行成功了。ALTER PROCEDURE [dbo].[ps_statbumen3]
@year nvarchar(4)
AS
declare @sql varchar(8000)
set @sql = 'select department,年龄段'
select @sql = @sql + ' , sum(case LatterEducation when ''' + Educationtype + ''' then 1 else 0 end) [' + Educationtype+ ']'
from (select distinct Educationtype from Educationtype) as a
set @sql = @sql + ' from (select *,dbo.agetime1(Birthday) 年龄段 from v_hdemployee ) as tb where year='+@year+' group by department,年龄段' exec(@sql)请问这个功能在VS2005里面怎么实现啊????
比如:
数据库里面有个基础表A: 表A 姓名 部门 学历 出生年月
A 后勤 高中 1986-1-1
B 后勤 初中 1984-3-7
C 管理 本科 1987-2-1
D 操作 专科 1976-2-1
. . . .
. . . .
要求动态的生成一下效果的表:
部门 年龄段 高中 初中 本科.......
后勤 20-30 3 4 3 .......
30-40 3 9 0 .......
40-50 0 30 3 .......
管理 20-30 9 2 2 ....... 存储过程我已经写完了,在sql里面执行成功了。ALTER PROCEDURE [dbo].[ps_statbumen3]
@year nvarchar(4)
AS
declare @sql varchar(8000)
set @sql = 'select department,年龄段'
select @sql = @sql + ' , sum(case LatterEducation when ''' + Educationtype + ''' then 1 else 0 end) [' + Educationtype+ ']'
from (select distinct Educationtype from Educationtype) as a
set @sql = @sql + ' from (select *,dbo.agetime1(Birthday) 年龄段 from v_hdemployee ) as tb where year='+@year+' group by department,年龄段' exec(@sql)请问这个功能在VS2005里面怎么实现啊????
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货