小编und*_*ica的帖子

新手的光标替换

我想知道游标的一般替换是什么。我看到的游标的一般实现是

DECLARE @variable INT, @sqlstr NVARCHAR(MAX)

DECLARE cursor_name CURSOR
FOR select_statement --essentially to get an array for @variable 
                     --usually it's a subset of unique ids for accounts, clients, parts, etc

OPEN cursor_name
FETCH NEXT FROM cursor_name INTO @variable
WHILE @@FETCH_STATUS = 0
BEGIN
     SET @sqlstr = N'
     /* some query that uses '+ str(@variable) +' to do dirty work
     such as: go through all our accounts, if it''s some subset (possible new cursor), 
     go through those accounts and connect this …
Run Code Online (Sandbox Code Playgroud)

sql-server cursors

6
推荐指数
2
解决办法
1476
查看次数

标签 统计

cursors ×1

sql-server ×1