About 1,000,000 results
Open links in new tab
  1. Syntax of for-loop in SQL Server - Stack Overflow

    May 20, 2011 · I am detailing answer on ways to achieve different types of loops in SQL server. FOR Loop DECLARE @cnt INT = 0; WHILE @cnt < 10 BEGIN PRINT 'Inside FOR LOOP'; SET @cnt = @cnt + 1; END; PRINT 'Done FOR LOOP';

  2. SQL WHILE loop with simple examples - SQL Shack

    Oct 25, 2019 · In this article, we learned the SQL WHILE loop with quite simple examples. We also virtualized and explained the examples with flowcharts. WHILE loop helps us to achieve iterative operations in SQL Server. At the same time, BREAK and CONTINUE statements can be used to control iteration of the WHILE loop in SQL Server.

  3. How do I loop through a set of records in SQL Server?

    In most cases you can easily write a single SQL query that will do what you need to get done in one action instead of looping through individual records. By using T-SQL and cursors like this : SET @MyCursor = CURSOR FOR. select top 1000 YourField from dbo.table. where StatusID = 7 . OPEN @MyCursor . FETCH NEXT FROM @MyCursor . INTO @MyField.

  4. WHILE (Transact-SQL) - SQL Server | Microsoft Learn

    Nov 22, 2024 · Sets a condition for the repeated execution of a SQL statement or statement block. The statements are executed repeatedly as long as the specified condition is true. The execution of statements in the WHILE loop can be controlled from inside the loop with the BREAK and CONTINUE keywords.

  5. Learn SQL: Intro to SQL Server loops - SQL Shack

    Jun 15, 2020 · SQL Server Loops and Dates. So far, we’ve covered the basics and how SQL Server loops function and how we combine statements like IF and PRINT with loops. Now we’ll use loops to do something useful. We want to print all dates between the two given dates.

  6. Loops in SQL Server - TutorialsTeacher.com

    In SQL Server, a loop is the technique where a set of SQL statements are executed repeatedly until a condition is met. SQL Server supports the WHILE loop. The execution of the statements can be controlled from within the WHLE block using BREAK and CONTINUE keywords. SQL Statement | statement_block | BREAK | CONTINUE.

  7. SQL 'FOR LOOP' Statement: A Comprehensive Tutorial

    Sep 24, 2023 · The 'FOR LOOP' statement in SQL is a control flow mechanism that allows a block of code to be executed repeatedly based on a condition. The loop will continue until the specified condition is met. FOR loop_counter IN [REVERSE] lower_limit..upper_limit LOOP {...statements...}

  8. SQL Server: FOR LOOP - TechOnTheNet

    Learn how to simulate the FOR LOOP in SQL Server (Transact-SQL) with syntax and examples. TIP: Since the FOR LOOP does not exist in SQL Server, this page describes how to simulate a FOR LOOP using a WHILE LOOP. In SQL Server, there is no FOR LOOP. However, you simulate the FOR LOOP using the WHILE LOOP.

  9. SQL | Loops - Codecademy

    Jan 12, 2025 · The syntax for using LOOP is as follows: LOOP -- SQL statements IF condition THEN EXIT; END IF; END LOOP; Here’s an example to print the value of counter from 1 to 5 using a LOOP :

  10. Mastering SQL Loops: A Practical Guide with Examples - Medium

    Sep 11, 2023 · SQL loops, specifically FOR loops, provide a means to execute a block of code repeatedly until a specified condition is met. These loops are commonly used in PL/SQL or other procedural...

  11. Some results have been removed
Refresh