Elliott W (11/17/2009)
You could try this:
SELECT *
FROM dbo.SomeTable
WHERE ( @Field1 IS NULL OR Field1 = @Field1 )
AND ( @Field2 IS NULL OR Field2 = @Field2 )
AND ( @Field3 IS NULL OR Field3 = @Field3 )
AND ( @Field4 IS NULL OR Field4 = @Field4 )
Provided that the search fields are NULL when unused and non-NULL when used.
You could, providing that performance is not a major concern. Take a look at the link that Nabha posted.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability