you probably want a stored porcedure:use northwindgocreate procedure spMyOrders@CustomerId char(5) = null,@employeeId int = nullasselect * from orderswhere (CustomerId = @CustomerId or @CustomerId is null) and (employeeId = @employeeId or @employeeId is null)goexec spMyOrders null, null -- all dataexec spMyOrders 'VINET', null -- all data that have 'VINET' for customerIdexec spMyOrders null, 6 -- all data that have 6 for employeeIdexec spMyOrders 'VINET', 6 -- all data that have 'VINET' for customerId and 6 for employeeIdgodrop procedure spMyOrders
Go with the flow & have fun! Else fight the flow