Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-06-15 : 07:59:54
|
| Hi guys,Can anybody tell me how to do looping in SQL?Regards,David |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-15 : 08:02:56
|
| [code]WHILE <Condition>Begin Statement 1 ... Statement nEND[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-16 : 02:40:16
|
quote: Originally posted by david_reinjal Hi guys,Can anybody tell me how to do looping in SQL?Regards,David
Can you tell me what you are trying to do in looping?MadhivananFailing to plan is Planning to fail |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-06-16 : 10:01:57
|
quote: Originally posted by harsh_athalye
WHILE <Condition>Begin Statement 1 ... Statement nEND Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
better would be:WHILE 1 < 2Begin print 'avoid loops in t-sql. better to use a set-based approach'END elsasoft.org |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-16 : 10:56:25
|
quote: Originally posted by jezemine
quote: Originally posted by harsh_athalye
WHILE <Condition>Begin Statement 1 ... Statement nEND Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
better would be:WHILE 1 < 2Begin print 'avoid loops in t-sql. better to use a set-based approach'END elsasoft.org
Well. That would end in endless loop MadhivananFailing to plan is Planning to fail |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-06-16 : 11:46:09
|
indeed. that's the point. that is, you keep reading the message until you get the point.  elsasoft.org |
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2007-06-16 : 16:53:31
|
declare a variable as a counter and initialize it to 0 or your starting point. And increment it after every loop exit. as thusdeclare @counter intset @counter = 0WHILE <Condition>Begin Statement 1 ... Statement nset @counter = @counter + 1END As Madhivanan said, what are you trying to loop through ??? |
 |
|
|
|
|
|