Solved

nested while in sql functions or stored procedures

Posted on 2011-02-16
2
504 Views
Last Modified: 2012-05-11
hi
I'm trying to nest a while statement inside another while statement
Is that possible?
0
Comment
Question by:Nabilbahr
2 Comments
 
LVL 1

Accepted Solution

by:
TheAnvilGroup earned 250 total points
ID: 34907857
Yes it is possible but If two or more WHILE loops are nested, the inner BREAK exits to the next outermost loop. All the statements after the end of the inner loop run first, and then the next outermost loop restarts.

0
 

Author Comment

by:Nabilbahr
ID: 34907985
The problem here is that the nested while is inside if statement
WHILE @x <= 6
		BEGIN
        select @Intgr  = t from @Arr where i = @x
	


			if @Intgr > 0 
				BEGIN
				UPDATE @Arr SET t = 1 WHERE i = 0
				UPDATE @Arr SET t = (select t from @ArrValues where i = @x) WHERE i = 1
				UPDATE @Arr SET t = (select t2 from @ArrValues where i = @x) WHERE i = 2
				END
				ELSE
				BEGIN
					set @bFlag = 0


	
		
		            Declare @j as int
					SET @j = 0
					declare @u as int
					select @u = t2 from @Arr where i = 6 --UBOUND array is 6
					--FOR NEXt
					WHILE @j < @u
					DECLARE @COMP1 AS INT
					DECLARE @COMP2 as INT  
					SELECT @COMP1 = dbo.GetStringingSupport(@j) from @arr where i = 1

                    



					END --while nested


				END

Open in new window

0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now