MSSQL Parameters
When I was working on a quick store procedure with optional parameters and preferred not to have to write dozens of if's in TSQL I came upon this page that made my life a little easier (a fairly simple trick, but I thought I'd share):
Excerpt:
ALTER PROCEDURE dbo.YourProcedureName
@value1 CHAR(100) = NULL,
@value2 CHAR(100) = NULL,
@value3 CHAR(100) = NULL,
@value4 CHAR(100) = NULL
AS
SELECT
column1,
column2,
column3,
column4
FROM
Table_Name
WHERE
((@value1 IS NULL) OR (column1 = @value1))
AND ((@value2 IS NULL) OR (column2 = @value2))
AND ((@value3 IS NULL) OR (column3 = @value3))
AND ((@value4 IS NULL) OR (column4 = @value4))