January 10, 2007 at 2:33 pm
I have a nest loop, but it only runs the inner loop, please help.
declare
@measureid int
declare @monthnum int
set @monthnum=0
set
@measureid=0
while
@monthnum<12--month loop begin
begin
set @monthnum=@monthnum+1
while @measureid<28
begin --measureid loop begin
select @monthnum
set @measureid=@measureid+1
end --measureid loop end
end
--month loop end
January 10, 2007 at 3:24 pm
declare @measureid int
declare @monthnum int
set @monthnum=0
set @measureid=0
while @monthnum<12--month loop begin
begin
set @monthnum=@monthnum+1
set @measureid = 0
while @measureid<28
begin --measureid loop begin
select @monthnum
set @measureid=@measureid+1
end --measureid loop end
end --month loop end
January 10, 2007 at 3:25 pm
May I ask why you are using code like this??? Sql server is build to handle sets of data, not procedural stuff.
January 10, 2007 at 3:33 pm
Thank you so so much, that's exact what I want.
In fact the inner loop is calling a dynamic block of code to do the calculations for 28 measures, and I need them for ervery month in a given year. Thanks again.
January 10, 2007 at 7:38 pm
Still don't see the need for loops and dynamic sql. Can you post the tables DDL some sample data and the required output from that data. I'm sure we can figure something out to make this run faster.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply