--不是很规范
create table a(a1 datetime,a2 datetime)
insert a values('2003-01-01','2003-08-23')
go
create table b(b1 int )
go
create proc test
as
declare @begin int,@end int
select @begin=month(a1),@end=month(a2) from a
while @begin<=@end
begin
insert b select @begin
set @begin=@begin+1
end
go
exec test
go
select * from b
insert tabB(b1)
select m from (select 1 as m
union all select 2
union all select 3
union all select 4
union all select 5
union all select 6
union all select 7
union all select 8
union all select 9
union all select 10
union all select 11
union all select 12
) A,(select a1,a2 from TabA where 你的条件) B where m between month(a1) and month(a2)