如何在T-SQL中获取受影响行的计数

时间:2015-05-25 05:46:16

标签: sql dynamicquery rows-affected

我在下面有一个存储过程:

ALTER PROCEDURE dbo.sp_DeleteRoecords
    @Conditions NVARCHAR(200)
AS
BEGIN
    DECLARE @Query NVARCHAR(2000) 

    SET @Query = 'DELETE FROM Customer Where ' + @Conditions
    EXEC (@Query)
END

执行@Query后如何获得受影响的行?

1 个答案:

答案 0 :(得分:1)

ALTER PROCEDURE dbo.sp_DeleteRoecords
    @Conditions NVARCHAR(200)
AS
BEGIN
    DECLARE @Query NVARCHAR(2000) 

    SET @Query = 'DELETE FROM Customer Where ' + @Conditions + ';Select @@rowcount'
    EXEC (@Query)
END

删除查询后添加@@ rowcount的语句。