Hi all,
I want to insert data(month&year) from 2014 till now to my SQL Server DB - into temp table using 2 while loop.
drop table #loop
create table #loop
(seq int identity(1,1),
[month] smallint,
[Year] smallint)
Declare @year int=2014
Declare @Month int = 1
Declare @Currentyear int =(select year(getdate()))
Declare @Currentmonth int =(select month(getdate()))
While (@year <= @Currentyear)
Begin
While ((@Month <= @Currentmonth and @year= @Currentyear )) or (@Month <= 12 and @year< @Currentyear )
Begin
insert into #loop([month] ,[year]
values(@Month,@year)
set @Month = @Month +1
End
set @year = @year +1
End
select * from #loop
For some reason I cant not get 2015 data .
Anyone have an idea why ?
Thanks