Once you get more than a couple of these, then yes: it starts to get pretty slow. In such cases, I tend to use generated TSQL - i.e.
DECLARE @sql nvarchar(4000)
SET @sql = /* core query */
IF @name IS NOT NULL
SET @sql = @sql + ' AND foo.Name = @name'
IF @dob IS NOT NULL
SET @sql = @sql + ' AND foo.DOB = @dob'
// etc
EXEC sp_ExecuteSQL @sql, N'@name varchar(100), @dob datetime',
@name, @dob
etc
Note that sp_ExecuteSQL caches query-plans, so any queries with the same args can potentially re-use the plan.
The downside is that unless you sign the SPROC, the caller needs SELECT permissions on the table (not just EXEC permissions on the SPROC).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…