存储过程如何返回 ROWCOUNT?

发布于 2024-09-24 00:43:53 字数 176 浏览 0 评论 0原文

我编写了存储过程,其中有 2 个插入查询和 1 个更新查询。其中,插入查询或更新查询都是同时执行的。现在我的问题是在每种情况下获取ROWCOUNT。假设如果执行插入操作,那么我希望存储过程将@@ROWCOUNT返回给调用应用程序,以便应用程序知道所需的操作是否正确执行。谁能建议/告诉我如何获取存储过程影响的行?

I have written stored procedure which has 2 Insert queries and 1 Update query inside it. Of all these,either insert queries or update query are executed at a time. Now my problem is to get ROWCOUNT in each case. Say suppose if insert operations are executed,then I want stored procedure to return @@ROWCOUNT to the calling application, so that the application will be aware of whether the required operations executed correctly or not. Can anyone suggest/tell me how can I get the rows affected from the stored procedure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ映画 2024-10-01 00:43:53

在存储过程中使用输出参数返回插入/更新的 RowCount。

有关如何使用输出参数的详细信息,请参阅 MSDN 链接

您可以有多个输出参数,因此您可以有 2 个不同的输出参数,每个参数用于插入,第三个用于更新语句。

示例:

CREATE PROCEDURE GetEmployeeData
   @employeeID INT,
   @managerID INT **OUTPUT**
AS
BEGIN
....
....

此外,您始终可以使用分隔符连接 2 个插入/更新的行计数,并将它们作为一个值返回,例如:“10;0” - 然而这是老式的“我不推荐”方法。

此外,您还可以创建一个表变量并返回表,其中行数 = 插入/更新数,列的值 = 受影响的 RowCount。

Use Output parameters in your stored procedures to return the RowCount of your inserts / updates.

Refer MSDN link for more information on how to use Output params

You can have multiple output params so you can have 2 different output params one each for your insert and the 3rd for your update statement.

Example:

CREATE PROCEDURE GetEmployeeData
   @employeeID INT,
   @managerID INT **OUTPUT**
AS
BEGIN
....
....

Additionally, you can always concatenate the rowcounts of your 2 Inserts / Update using delimiters and return them as one value eg: "10;0" - However that is the old fashioned and "I would not recommend" approach.

Also, you could create a table variable and return the table with rows = number of Inserts / updates and the value of the column = RowCount affected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文