What is the syntax of a for
loop in TSQL?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- What does an “empty line with semicolon” mean in C
There is no for-loop, only the while-loop:
How about this:
... of course you could put an incremental counter inside it if you need to count.
While Loop example in T-SQL which list current month's beginning to end date.
Extra Info
Just to add as no-one has posted an answer that includes how to actually iterate though a dataset inside a loop, you can use the keywords OFFSET FETCH.
Usage
Simple answer is
NO !!
.WHILE :
GOTO :
I always prefer
WHILE
overGOTO
statement.For loop is not officially supported yet by SQL server. Already there is answer on achieving FOR Loop's different ways. I am detailing answer on ways to achieve different types of loops in SQL server.
FOR Loop
If you know, you need to complete first iteration of loop anyway, then you can try DO..WHILE or REPEAT..UNTIL version of SQL server.
DO..WHILE Loop
REPEAT..UNTIL Loop
Reference