Solved

nested while in sql functions or stored procedures

Posted on 2011-02-16
2
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

752 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