October 13, 2008 at 9:05 pm
You should tell us why you'll need nested While loops... typically, that's a recipe for a huge RBAR performance problem and it can usually be avoided. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
October 13, 2008 at 9:11 pm
You need to include the intial value of @j-2 in the @I loop or it just counts down in one iteration of @I and stays there.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 13, 2008 at 9:21 pm
Jeff Moden (10/13/2008)
Last, but not least, you need to include the intial value of @j-2 in the @I loop or it just counts down in one iteration of @I and stays there.
Agreed - that's more than likely where the confusion is.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
October 13, 2008 at 11:00 pm
hi,
your code is working perfect.
you set the variable value to it's condition then what to do.
SET @i = 5
SET @j-2 = 3
SET @name ='test'
WHILE @i > 0
BEGIN
print @i
WHILE @j-2>0
BEGIN
Print @name + '-' + cast(@j as varchar)
--here you set j value b'cz it's global variable
END
--now here set and check code
SET @j-2 = 3
SET @i = @i -1
END
End
if i m getting right then?
thnx
October 14, 2008 at 5:26 am
Still, the code is doomed to be comparatively slow because of the loops. If we knew the actual problem this was supposed to solve, perhaps we could find a proper set based solution for the problem. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
October 14, 2008 at 2:02 pm
By this time I think the PO is not longer with us (no pun intended)
* Noel
October 14, 2008 at 7:06 pm
noeld (10/14/2008)
By this time I think the PO is not longer with us (no pun intended)
Heh, agreed. It's a shame, too. I would have liked to take a crack at whatever they thought they needed a double loop for... maybe even if it was homework.:P
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply