如何在sql中返回受上次查询影响的记录数 [英] How to return number of record affected by last query in sql
问题描述
在我的存储过程中,我使用了2个insert语句。当我使用executenonquery()执行sp时,它返回受2个语句影响的行数。假设查询1影响的行数为2,查询2影响的行数为3.It返回5.我想要最后查询的结果。这只是3。如何做?
SET NOCOUNT ON
- 第一次查询
SET NOCOUNT 关闭
- 第二次查询
Quote:当SET NOCOUNT为ON时,计数(表示受Transact-影响的行数)不返回SQL语句)。当SET NOCOUNT为OFF时,将返回计数。
- MSDN
希望,它有帮助:)
In my stored procedure I have used 2 insert statement.When I am executing sp using executenonquery(),it return me number of row affected by 2 statement. Suppose number of row affected by Query 1 is 2 and number of row affected by Query 2 is 3.It returns me 5.I want last query's result.That is 3 only.How to do that?
Try this-
SET NOCOUNT ON --first query SET NOCOUNT OFF --second query
Quote:When SET NOCOUNT is ON, the count (indicating the number of rows affected by a Transact-SQL statement) is not returned. When SET NOCOUNT is OFF, the count is returned.
--MSDN
Hope, it helps :)
这篇关于如何在sql中返回受上次查询影响的记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!