About 866,000 results
Open links in new tab
  1. 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.

  2. SQL WHILE LOOP Examples and Alternatives - MSSQLTips.com - SQL Server

    Mar 4, 2022 · In this article, we will look at examples of a SQL Server WHILE loop in T-SQL and discuss alternatives like a CTE and cursor.

  3. 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.

  4. SQL While loop: Understanding While loops in SQL Server - SQL

    Nov 6, 2019 · If you want to repeatedly execute a particular SQL script, the SQL While loop is the way to go. The article explains how to use the SQL While loop in Microsoft SQL Server to perform a variety of tasks ranging from record insertion to pagination.

  5. sql server - While loop with multiple conditions in T-SQL - Stack Overflow

    WHILE loops are totally valid to use as long as they're not being used out of ignorance of set based operations. don't you mean between -10 and 10? You must look at declaration of WHILE statement: { sql_statement | statement_block | BREAK | CONTINUE } . First of all you can use complex Boolean_expression as Dan said:

  6. In SQL Server, how to create while loop in select

    Nov 10, 2013 · SET @tempDATA = SELECT data from table1 where id = @teampID. SET @LoopNUM = 0. WHILE @LoopNum< len(@tempDATA) / 2. BEGIN. INSERT INTO table2 (id, data) VALUES( @tempID, SUBSTRING(@tempDATA, @LoopNum * 2 +1, 2)) SET @LoopNum = @LoopNum + 1. END. I don't want to use CURSOR because it's too slow, I have many data. Does anyone has good idea for it?

  7. SQL Server WHILE Loop (with Examples) - Database.Guide

    Jul 29, 2024 · The WHILE loop in SQL Server is a control-flow statement that allows us to repeatedly execute a block of code as long as a specified condition is true. It’s useful for iterative tasks and processing data in batches. The basic syntax goes like this: -- Code to be executed. Key points: The condition is evaluated before each iteration.

  8. SQL Server: WHILE LOOP - TechOnTheNet

    Syntax. The syntax for the WHILE LOOP in SQL Server (Transact-SQL) is: WHILE condition BEGIN {...statements...} END; Parameters or Arguments condition The condition is tested each pass through the loop. If condition evaluates to TRUE, the loop body is executed. If condition evaluates to FALSE, the loop is terminated. statements

  9. SQL Server WHILE - How To Create Loop in SQL Server - SQL Server Tutorial

    The following illustrates the syntax of the WHILE statement: WHILE Boolean_expression { sql_statement | statement_block} Code language: SQL (Structured Query Language) (sql) In this syntax: First, the Boolean_expression is an expression that evaluates to TRUE or FALSE. Second, sql_statement | statement_block is any Transact-SQL statement or a ...

  10. T-SQL WHILE in SQL Server - T-SQL Tutorial

    WHILE statement is used together with a condition and forms a loop. Basically WHILE sets a condition for repeated execution within itself of an SQL statement or a block of statements. As long as the specified condition is true, the SQL statements are executed repeatedly.

  11. Some results have been removed
Refresh