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).
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).VB Code:
DECLARE @StartDate DateTime, @EndDate DateTime, @IsNewCust bit; SET @StartDate = '2007-09-01 00:00:00' SET @EndDate = '2007-09-30 23:59:59' SET @IsNewCust = 0 SELECT * FROM Tickets WHERE (Tickets.SaleDate BETWEEN @StartDate AND @EndDate) AND (Tickets.IsNewCustomer = @IsNewCust)
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.




Reply With Quote