Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

nested while in sql functions or stored procedures

Posted on 2011-02-16
2
Medium Priority
?
513 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 1000 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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

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…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

722 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