日期:2014-05-17 浏览次数:20729 次
with tb(dptid, dptname,age1,age2,age3,age4,age5,[year],[month])
as(
select '01010121','狼牙',0,0,0,0,0,2012,1 union all
select '01010121','狼牙',0,0,-1,0,-1,2012,2 union all
select '01010121','狼牙',0,0,-1,0,-1,2012,5 union all
select '01010121','狼牙',0,0,0,0,0,2012,6 union all
select '01010121','狼牙',0,0,-1,0,-1,2012,8 union all
select '01010121','狼牙',0,0,0,5,5,2012,9 union all
select '01010121','狼牙',1,0,0,0,1,2012,10 union all
select '01010121','狼牙',0,0,-1,10,9,2012,11 union all
select '01010121','狼牙',0,0,-2,-1,-3,2012,12 union all
select '010151', '新兵',0,1,2,0,3,2012,1 union all
select '010151', '新兵',0,2,-1,0,1,2012,3 union all
select '010151', '新兵',0,2,-1,0,1,2012,4 union all
select '010151', '新兵',0,2,-1,0,1,2012,5 union all
select '010151', '新兵',0,2,-1,0,1,2012,6 union all
select '010151', '新兵',0,2,-1,0,1,2012,7 union all
select '010151', '新兵',0,2,-1,0,1,2012,8 union all
select '010151', '新兵',0,2,-1,0,1,2012,9 union all
select '010151', '新兵',0,2,-1,0,1,2012,10)
select tb1.* from tb tb1
union all
select tb1.dptid, tb1.dptname,tb1.age1,tb1.age2,tb1.age3,tb1.age4,tb1.age5,tb1.[year],c.number from tb tb1 , master..spt_values c where c.type='p' and c.number between 1 and 12
and (select count(1) from tb tb2 where tb2.dptid=tb1.dptid and tb2.dptname=tb1.dptname and tb2.[year]=tb1.[year] and tb2.[month]=c.number)<1
and (select max(tb2.[month]) from tb tb2&