日期:2014-05-17 浏览次数:20541 次
select
a.工号,a.姓名,
max(case when c.保险内码=1 then b.个人负担比率 else '' end) as 养老保险个人负担比率,
max(case when c.保险内码=1 then b.个人负担金额 else '' end) as 养老保险个人负担金额,
max(case when c.保险内码=2 then b.个人负担比率 else '' end) as 医疗保险个人负担比率,
max(case when c.保险内码=2 then b.个人负担金额 else '' end) as 医疗保险个人负担金额,
max(case when c.保险内码=3 then b.个人负担比率 else '' end) as 失业保险个人负担比率,
max(case when c.保险内码=3 then b.个人负担金额 else '' end) as 失业保险个人负担金额
from
员工基本资料表 a,
员工保险资料表 b,
保险基本资料表 c
where
a.员工内码=b.员工内码
and
b.保险内码=c.保险内码
create table 员工基本资料表
(员工内码 int,工号 varchar(10),姓名 varchar(10))
create table 员工保险资料表
(内码 int,员工内码 int,保险内码 int,个人负担比率 varchar(5),个人负担金额 varchar(5))
create table 保险基本资料表
(保险内码 int,代号 varchar(10),名称 varchar(10))
insert into 员工基本资料表
select 1,'130001','张三' union all
select 1,'130002','李四' union all
select 1,'130003','王五' union all
select 1,'130004','赵六'
insert into 员工保险资料表
select 1,1,1,'2%','20' union all
select 2,1,2,'3%','30' union all
select 3,1,3,'5%','50' union all
select 4,2,1,'2%','20' union all
select 5,2,2,'3%','30' union all
select 6,3,1,'2%','20' union all
select 7,4,1,'2%','20' union all
select 8,4,2,'3%','30' union all
select 9,4,3,'5%','50'
insert into 保险基本资料表
select 1,'001','养老保险' union all
select 2,'002','医疗保险' union all
select 3,'003','失业保险'
declare @tsql varchar(6000)
select @tsql=isnull(@tsql+',','')
+'max(case when c.名称='''+名称+''' then a.个人负担比率 else '''' end) '''+名称+'个人负担比率'', '
&n