I have a stored procedure similar to this, which returns rows based on whether the IsNewCustomer Bit is set to true or false (hard coded in this sample but called with parameters from a VB app in the original).
VB Code:
  1. DECLARE @StartDate DateTime, @EndDate DateTime, @IsNewCust bit;
  2. SET @StartDate = '2007-09-01 00:00:00'
  3. SET @EndDate = '2007-09-30 23:59:59'
  4. SET @IsNewCust = 0
  5.  
  6. SELECT * FROM Tickets
  7. WHERE    
  8.     (Tickets.SaleDate BETWEEN @StartDate AND @EndDate) AND
  9.     (Tickets.IsNewCustomer = @IsNewCust)
Right now when I run this procedure I have to pass the IsNewCust parameter to specify which records I want back, which works great but I also want a third option to get all the records (both 0's and 1'’s).

How can that be done when the stored procedure is always looking for the parameters it contains. Is there a way to set optional parameters in SQL?

By the way this is SQL Server 2005 if that makes a difference.