You don't really want, or need, to be doing this in dynamic SQL in the Sproc.create procedure dbo.searchComplaintdetails( @FirstName nvarchar(50), @DueDate DateTime)asselect Customers.CustomerFirstName as Name, ComplaintLog.LogDate, ComplaintLog.LogID, ComplaintLog.ComplaintStatus, ComplaintLog.DueDate, ComplaintCategories.CategoryNamefrom dbo.ComplaintLog Join dbo.ComplaintCategories on ComplaintLog.CategoryID=ComplaintCategories.CategoryID join dbo.Customers on ComplaintLog.CustomerID=Customers.CustomerID where ComplaintLog.IsActive=1 AND ( NullIf(@FirstName, '') IS NULL OR Customers.CustomerFirstName LIKE @FirstName + '%' ) AND ( @DueDate IS NULL OR ( @DueDate < ComplaintLog.DueDate AND ComplaintLog.DueDate < DATEADD(Day, 1, @DueDate) ) )
Kristen