The best way to do this is below. However, you MUST monitor for parametric sniffing. This will become a problem, as your table will become larger and will randomly affect runtime. This is an annoying problem that may appear. Use the code below.
CREATE PROCEDURE GetPaymentStatus @StatusID varchar(50)=NULL AS BEGIN SET NOCOUNT ON; DECLARE @StatusId_local varchar(50) SET @StatusID_local = @StatusId SELECT MyField1, MyField2 FROM Payment_Table WHERE Payment_Table.Status=@StatusID _local OR (@StatusID_local IS NULL AND Payment_Table.Status IS NULL) END
See this article for an article or the value of the snap parameter for google sql code for more information.
source share