The user can search for a client by the first, last and, possibly, when entering the city.
Is it possible to write SQL that matches CITY only if the user entered one without using dynamic SQL?
CREATE PROCEDURE [dbo].[SearchCustomer] @FirstName varchar(30) --REQUIRED @LastName varchar(30)--REQUIRED @City varchar(30) --OPTIONAL AS SELECT * FROM CUSTOMER C WHERE C.FirstName = @FirstName AND C.LastName = @LastName AND C.City = IsNull(@City, C.City) --This won't Work if CITY is optional in the database
Chadd source share