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

后端 未结 11 642
轮回少年
轮回少年 2020-12-04 07:47

Is there anyway to loop through a table variable in T-SQL?

DECLARE @table1 TABLE ( col1 int )  
INSERT into @table1 SELECT col1 FROM table2

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 07:57

    You can loop through the table variable or you can cursor through it. This is what we usually call a RBAR - pronounced Reebar and means Row-By-Agonizing-Row.

    I would suggest finding a SET-BASED answer to your question (we can help with that) and move away from rbars as much as possible.

提交回复
热议问题