
Syntax of for-loop in SQL Server - Stack Overflow
May 20, 2011 · SQL is a very different language compared to what you're used to. It's focused on what, not how. You tell SQL Server what results you want, and let it figure out how to produce …
How do I loop through a set of records in SQL Server?
224 How do I loop through a set of records from a select statement? Say I have a few records that I wish to loop through and do something with each record. Here's a primitive version of my …
How can INSERT INTO a table 300 times within a loop in SQL?
In SQL, you should generally try to write set-based code, not procedural, step by step code. So, the SQLish thing to ask for is "how do I insert 300 rows into my table, where each row gets a …
sql - create while loop with cte - Stack Overflow
Oct 17, 2012 · how to create sql server cte from a while loop my loop like this declare @ind as int declare @code as nvarchar set @ind = 0 while @ind < 884 begin select @ind = @ind + 1 ...
t sql - How can I use loop (WHILE statement) for "WITH" clause …
Jul 8, 2012 · In my T-SQL code, I use WITH for reading data from a table. After reading, I want use WHILE to get items (first item, second item, ...) from WITH results and delete items from it. …
Can I loop through a table variable in T-SQL? - Stack Overflow
This is actually why I want to use a table variable instead of a cursor. I generally look for a way to get my intended result using a JOIN on a table variable, but if I can't find a way to use a JOIN, …
SQL Server FOR EACH Loop - Stack Overflow
Jan 1, 2010 · SQL is primarily a set-orientated language - it's generally a bad idea to use a loop in it. In this case, a similar result could be achieved using a recursive CTE:
sql server - When should I use an INNER -LOOP- JOIN instead of …
43 LOOP | HASH | MERGE are Join hints, specifying that the join in the query should use looping, hashing, or merging. Using LOOP |HASH | MERGE JOIN enforces a particular join between …
sql - Updating database records in a loop? - Stack Overflow
Feb 19, 2009 · declare begin for i in (select * from emp) loop if i.sal=1300 then update emp set sal=13000; end if; end loop; end; This code is updating all the records with salary 13000.
In SQL Server, how to create while loop in select
Nov 10, 2013 · In SQL Server, how to create while loop in select Asked 11 years, 11 months ago Modified 9 years, 2 months ago Viewed 284k times