Saturday, September 17, 2016

Add a new, conditional flag to a WHERE clause in T-SQL at a SELECT for filtering.

ALTER PROCEDURE [dbo].[Whatever]
   @Iwasalwayshere INT,
   @Iamnew VARCHAR(50) = NULL

AS
BEGIN
   SELECT * FROM Gunk
   WHERE MatchId = @Iwasalwayshere
   AND (@Iamnew ISNULL OR BlahBlahBlah = @Iamnew)
   AND IsActive = 1
END

No comments:

Post a Comment