I have a stored procedure with a number of parameters. I would like to write my query so that it joins with certain tables but only if a particular parameter has a value. Take
SELECT Customers.CustomerName, Customers.Country, Orders.OrderID
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
WHERE Country= @MyOptionalCountryArg or @MyOptionalCountryArg is null;