sql server - Can I loop through a table variable in T-SQL? -


Is there any way of loop through a table variable in T-SQL?

  DECLARE @  

I also use the cursor, but the cursor seems less flexible than the table variable.

  Cursor before 1 selection select Colonel 1 cursor for cursor open cursor 1 curious cursor 1 next to  

I use the same way as a cursor I would like to be able to use table variables In this way, I can execute some queries on table variable in one part of the process, and then execute some code for each row in the table variable.

Any help is greatly appreciated.

Try this:

  DECLARE @ RowsToProcess int decarary @CurrentRow int decalare @ SelectCol1 int Decalare @ table1 table (not roid int no zero primary key identification (1,1), col1 int) INSERT @ table1 (col1) SELECT col1 to table 2 SET @ RowsToProcess = @@ ROWCOUNT SET @ CurrentRow = 0 WHILE @ CurrentRow & lt; @ RowsToProcess BEGIN SET @ CurrentRow = CurrentRow + 1 Select selectCol1 = from col1 @ table1 WHERE ROWID = CurrentCrow = - Here's your talk - end  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -