Code error in a SQL Server While-If Loop
<p>I know that there are other posts with code that solve my problem but I don't want to take another's code so I'm trying to do it by myself and I'm stuck with the month not increasing problem, so if anyone can help me with that mistake it will be awesome.</p>

<p>The problem is:</p>

<p>I have to populate the table Time from year 1990 to 2016 with all the months and days, I have already achieved that the code works and it populates correctly the years and the days but months increases to January (1) and  then is not increasing so the table is filled with all months being January (LOL)</p>

<p>Here's my code:</p>

<pre><code>create table Time
(
    Year int, 
    Month int,
    Day int
)

create procedure pTime
as
    declare @year int, @month int, @day int;
    set @year = 1990;
    set @month = 12;
    set @day = 10;

while(@year&lt;=2016)
Begin

    If(@day = 29)
    Begin

        set @month = @month + 1;

        If(@month = 13)
        Begin

            set @month = 1;
            set @day = 1;
            set @year = @year + 1;

            insert into Time values (@year, @month, @day);
        End
    End 

    else
    Begin
        If(@day = 29)
        Begin

            set @month = @month + 1;
            set @day = 1;

            insert into Time values (@year, @month, @day);
        End

        Else    
        Begin

            insert into Time values (@year, @month, @day);

            set @day = @day + 1;
        End
    End
End
</code></pre>

<p>Any idea where is my mistake or any suggestion?</p>