码迷,mamicode.com
首页 > 其他好文 > 详细

找出缺数据的月份

时间:2014-05-23 11:20:05      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:style   c   code   ext   color   a   

declare @last table(year1 varchar(100),companycode1 varchar(100),lastmonth varchar(100))
declare @now  table(year varchar(100),companycode varchar(100), month varchar(100))
declare @temp table(month varchar(100));
declare @year int
set @year=2009
insert into @temp (month) values(‘01‘);
insert into @temp (month) values(‘02‘);
insert into @temp (month) values(‘03‘);
insert into @temp (month) values(‘04‘);
insert into @temp (month) values(‘05‘);
insert into @temp (month) values(‘06‘);
insert into @temp (month) values(‘07‘);
insert into @temp (month) values(‘08‘);
insert into @temp (month) values(‘09‘);
insert into @temp (month) values(‘10‘);
insert into @temp (month) values(‘11‘);
insert into @temp (month) values(‘12‘);
insert into @last   
select * from (
select Year,companycode   from
ACV_Gr with(nolock) where [year]=@year  GROUP BY companycode,Year 
)a inner join @temp t on 1=1
print 1
--select * from @last order by companycode1,lastmonth
insert into @now 
select Year,companycode,Month=substring(‘0‘+month,len(month) ,5)     from
ACV_BookDetail_2009 with(nolock) where [year]=@year  GROUP BY companycode,Year,Month
--select * from @now order by companycode,month
print 2
delete  @last   where exists(select * from @now a where a.year= YEAR1 AND a.companycode= companycode1 and a.month=lastmonth)
select * from  @last order by companycode1,lastmonth
 
 
 

找出缺数据的月份,布布扣,bubuko.com

找出缺数据的月份

标签:style   c   code   ext   color   a   

原文地址:http://www.cnblogs.com/zgan/p/3737470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!