SR0015: Extract deterministic function calls from WHERE predicates
RuleId | SR0015 |
Category | Microsoft.Performance |
Breaking Change | Non-breaking |
In the first example, the stored procedure includes a deterministic function call, ABS(@param1), in the WHERE predicate. In the second example, a temporary variable holds the result of the call.
CREATE PROCEDURE [dbo].[Procedure2WithWarning] @param1 INT = 0, AS BEGIN SELECT [c1], [c2], [c3], [SmallString] FROM [dbo].[Table1] WHERE [c2] > ABS(@param1) END CREATE PROCEDURE [dbo].[Procedure2Fixed] @param1 INT = 0, AS BEGIN DECLARE @AbsOfParam1 INT SET @AbsOfParam1 = ABS(@param1) SELECT [c1], [c2], [c3], [SmallString] FROM [dbo].[Table1] WHERE [c2] > @AbsOfParam1 END