指纹库中有两张表一张是用户表字段如下
code name
2001 张三
2002 李四
2003 王五
.....
一张是指纹打卡记录表字段如下
编号 打卡时间
2001 2013/7/15 7:42
2001 2013/7/15 18:00
2002 2013/7/16 7:45
2002 2013/7/16 18:03
2003 2013/7/17 7:32
2001 2013/7/22 7:49
2003 2013/7/22 18:07
.....
现在我想把两张表转换成考勤表如下

请问我要这sql要怎么写?sql弱到爆想了一下午硬没搞出来。
考勤 打卡
------解决方案--------------------
这样吗:
--drop table t
--drop table tb
--go
create table t(code int, name varchar(20))
insert into t
select 2001, '张三'
union all select 2002 , '李四'
union all select 2003 , '王五'
create table tb(编号 int,打卡时间 datetime)
insert into tb
select 2001 ,'2013/7/15 7:42'
union all select 2001, '2013/7/15 18:00'
union all select 2002, '2013/7/16 7:45'
union all select 2002, '2013/7/16 18:03'
union all select 2003, '2013/7/17 7:32'
union all select 2001, '2013/7/22 7:49'
union all select 2003, '2013/7/22 18:07'
go
select t.name,tt.v,
max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='01'
then convert(varchar(5),打卡时间,114)
else null
end) as '01',
max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='02'
then convert(varchar(5),打卡时间,114)
else null
end) as '02',
max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='03'
then convert(varchar(5),打卡时间,114)
else null
end) as '03',
max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='04'
then convert(varchar(5),打卡时间,114)
else null
end) as '04',
max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='05'
then convert(varchar(5),打卡时间,114)
else null
end) as '05',
max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='06'
then convert(varchar(5),打卡时间,114)
else null
end) as '06',
max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='07'
then convert(varchar(5),打卡时间,114)
else null
end) as '07',
max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='08'
then convert(varchar(5),打卡时间,114)