Skip to content

Instantly share code, notes, and snippets.

@erikdarlingdata
Created March 6, 2020 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikdarlingdata/526e151eb6791ef168d0998fd205bc4d to your computer and use it in GitHub Desktop.
Save erikdarlingdata/526e151eb6791ef168d0998fd205bc4d to your computer and use it in GitHub Desktop.
CREATE INDEX whatever ON dbo.Users(Reputation);
GO
ALTER FUNCTION dbo.BeatIt(@Reputation INT)
RETURNS TABLE
AS
RETURN
SELECT *
FROM dbo.Users AS u
WHERE u.Reputation = @Reputation;
GO
ALTER PROCEDURE dbo.BeatThat(@Reputation INT)
AS
SET NOCOUNT, XACT_ABORT ON;
BEGIN
DECLARE @ReputationFix INT;
SET @ReputationFix = @Reputation;
IF @ReputationFix NOT BETWEEN 1 AND 2000000
BEGIN
SET @ReputationFix = 1;
END
SELECT *
FROM dbo.BeatIt(@ReputationFix) AS bi;
END;
EXEC dbo.BeatThat @Reputation = 1;
EXEC dbo.BeatThat @Reputation = 2;
DBCC FREEPROCCACHE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment