SQL Nested Loop -


i got stuck in nested loop , appreciate advice.

declare @monthnumber integer, @loopcounter integer  set @monthnumber = 0 set @loopcounter = 1  while @monthnumber <= 13 begin      while @loopcounter <=100 begin      @loopcounter = @loopcounter +1      end  @monthnumber = @monthnumber + 1  end 

i've abbreviated code sample above; have 2 loops in main sql query. inner loop identify different records in table 100 times, , outer loop add 1 month @monthnumber variable when code runs, return 100 records each of 13 months 1 table. when run code, first inner loop runs perfectly, ends without continuing next month via adding 1 @monthnumber. suggestions?

you not reset @loopcount variable 1:

declare @monthnumber integer, @loopcounter integer  set @monthnumber = 0 set @loopcounter = 1  while @monthnumber <= 13 begin      while @loopcounter <=100 begin      @loopcounter = @loopcounter +1      end  @monthnumber = @monthnumber + 1  set @loopcounter = 1  end 

Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -