如何遍历一组结果 [英] How to loop through a set of result
本文介绍了如何遍历一组结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码,如何循环返回的结果集?
i have the following codes, how can i loop through the result set returned?
SELECT @sql = (SELECT dbo.CRF_Project.DocStatus from vsCustomizationRequest.dbo.CRF_Project where CustomerID = '1') --this is the result returned from a table
--loop start here
IF(@sql = '0')
SET @row = CONVERT(INT,(COUNT(@sql)))
SET @ColumnName = 'sta0'
SET @statement = 'UPDATE ['+@TABLE+'] SET '+@ColumnName+' = '''+@row+''''
EXEC @statement
推荐答案
您正在寻找 CURSOR [ ^ ]
几个参考:
http://www.mssqltips.com/sqlservertip/1599/sql-server-cursor -example / [ ^ ]
sql server中的Cursor是什么 [ ^ ]
http://stackoverflow.com/ question / 11852782 / t-sql-loop-over-query-results [ ^ ]
you are looking for CURSOR [^]
few references:
http://www.mssqltips.com/sqlservertip/1599/sql-server-cursor-example/[^]
What is Cursor in sql server[^]
http://stackoverflow.com/questions/11852782/t-sql-loop-over-query-results[^]
更多链接 -
简单的光标示例 [ ^ ]
简单的例子光标 [ ^ ]
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=142325 [ ^ ]
Some more links -
Simple cursor example[^]
Simple example of a cursor[^]
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=142325[^]
这篇关于如何遍历一组结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文