| Author |
Topic |
|
BorisCallens
Yak Posting Veteran
50 Posts |
Posted - 2008-04-29 : 08:00:28
|
| Hi,Is it possible to have a do [sql] while statementinstead of a while [sql] do?The difference being the first one has at least one run before the looping test is done and the second one is tested before a single query is done.When searching, the second one is the one you always find. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-29 : 08:03:29
|
No. There is no DO in T-SQL.Why don't you make the WHILE thingy part of an IF-statement if you need your logic this way? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-29 : 08:08:12
|
| Whats your full scenario? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-29 : 08:29:47
|
WHILE 1 = 1BEGIN ... Code here If Something IS True BREAKEND E 12°55'05.25"N 56°04'39.16" |
 |
|
|
BorisCallens
Yak Posting Veteran
50 Posts |
Posted - 2008-04-29 : 08:34:03
|
| Thx for the answers.Yes, I'm implementing it with a break now.But breaking in loops is considered bad programming practice, so I wanted to do avoid it. But it seems there's no way to do it differently. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-04-29 : 08:40:07
|
quote: Originally posted by Peso No. There is no DO in T-SQL.
All I could think of is Yoda when I saw that. http://www.quotedb.com/quotes/42I guess T-SQL and the ways of the Jedi do not mix.For a Jedi, there is no TRY, only DO.In T-SQL, there is no DO, but there is a TRY! (In SQL 2005+, anyway) ...- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
BorisCallens
Yak Posting Veteran
50 Posts |
Posted - 2008-04-29 : 09:14:23
|
| Haha.Ah.. ppl and their amazing powers to know a complete movie series by heart. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-04-29 : 18:47:42
|
There are plenty of ways to avoid using a break if you want to: DECLARE @Continue BIT-- Prime conditionIF EXISTS (SELECT * FROM Foo WHERE Bar = Yak)BEGIN SET @Continue = 1ENDELSEBEGIN SET @Continue = 0ENDWHILE @Continue = 1BEGIN-- Do Stuff -- Reset condition IF EXISTS (SELECT * FROM Foo WHERE Bar = Yak) BEGIN SET @Continue = 1 END ELSE BEGIN SET @Continue = 0 ENDEND |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-04-29 : 18:54:46
|
eh, just use break. so much cleaner. elsasoft.org |
 |
|
|
|