如何在sql中返回受上次查询影响的记录数 [英] How to return number of record affected by last query in sql

查看:259
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆