@@rowcount
After each Transact-SQL statement, the server sets the value of this variable to the total number of records affected by it. It can be used to verify the success of selected operations:
select Make, Model, EqTypeid into OldEquipment from Equipment where EqTypeid = 2 if @@rowcount = 0 Print "No rows were copied!"
Note |
Certain statements (like the If statement) will set @@rowcount to 0, and certain statements (like Declare) will not affect it. |
Rowcount_big() is a function introduced in SQL Server 2000. It returns the number of affected records in the form of a bigint number.
注意在select 和 @@rowcount 之间不要加任何语句,例如
select top 1 @RatePlanID = RatePlanID from RatePlan where CarrierID = @CustID and isInBound = @IsInBound
if (@@rowcount = 0)
这两句之间如果加一句 select @sameRatePlanID=@RatePlanID
@@rowcount 会被影响到,导致对select的结果检查不对。