首页 > 代码库 > 找出缺数据的月份
找出缺数据的月份
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。