SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 for next loop
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

daviddeldave
Starting Member

United Kingdom
28 Posts

Posted - 03/10/2003 :  11:57:01  Show Profile
In sql what is the equivalent for the for next loop in vb?

David Mercer

Page47
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 03/10/2003 :  12:09:43  Show Profile
SQL is not a procedural language and thus contains no control-of-flow constructs.

Transact-SQL is a SQL Server specific extension of SQL. It does contain some control-of-flow language bits and pieces. You can read about that in Books Online by searching on "control-of-flow language".

Jay White
{0}
Go to Top of Page

robvolk
Most Valuable Yak

USA
15676 Posts

Posted - 03/10/2003 :  12:31:22  Show Profile  Visit robvolk's Homepage
You can also use tables that can substitute values for the numbers in a loop. Search SQL Team for "tally" or "sequence" and you'll find a number of examples.

Go to Top of Page

rharmon
Starting Member

41 Posts

Posted - 03/10/2003 :  14:00:38  Show Profile
Begging your pardons, rob and page, but is this kinda what you are looking for?

declare @counter int
set @counter = 0
while @counter < 20
begin
set @counter = @counter + 1
print @counter
end

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 03/10/2003 :  14:01:45  Show Profile
Wouldn't the following by sysnonomus?

FOR I=1 to 10
...some Code
NEXT I

SET I = 1
WHILE I < 11
BEGIN
...some Code
SET I = I + 1
END

What's the difference?

Brett

8-)

Go to Top of Page

Page47
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 03/10/2003 :  14:21:16  Show Profile
quote:

Begging your pardons, rob and page, but is this kinda what you are looking for?


Nope. I'm not looking for anything.

quote:

SET I = 1
WHILE I < 11
BEGIN
...some Code
SET I = I + 1
END


I think T-SQL would prefer an @I ...

Jay White
{0}
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 03/10/2003 :  14:29:28  Show Profile
My Bad Jay, Declare @I Int, it is.

But isn't that construct a control of flow, like a FOR/NEXT?

Brett

8-)



Go to Top of Page

robvolk
Most Valuable Yak

USA
15676 Posts

Posted - 03/10/2003 :  14:33:08  Show Profile  Visit robvolk's Homepage
Yeah, it is, but as Jay said it's not really SQL, it's an extension that T-SQL provides.

Go to Top of Page

Page47
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 03/10/2003 :  14:46:28  Show Profile
... and daviddeldave did not ask for a t-sql extension ...

sql is to vb as apples is to oranges.

Microsoft spray paints their apples orange, which leads to much confusion ...

Jay White
{0}
Go to Top of Page

daviddeldave
Starting Member

United Kingdom
28 Posts

Posted - 03/12/2003 :  14:39:30  Show Profile
Thanks the while loop is what I was looking for.

Regards

David Mercer
Go to Top of Page

JustinBigelow
SQL Gigolo

USA
1157 Posts

Posted - 03/12/2003 :  14:52:19  Show Profile
quote:

sql is to vb as apples is to oranges.



Is that one of those SAT analogy questions?

Justin

Expect 0x80040106
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000