Solved

nested while in sql functions or stored procedures

Posted on 2011-02-16
2
505 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

786 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