• Dynamic SQL is the last thing to do. I use and prefer the following way;

    SELECT [Name],

    [Color],

    [ListPrice],

    [ModifiedDate]

    FROM [Production].[Product]

    WHERE ([Name] LIKE case when @Name is Null then [Name] else @Name end)

    AND ([Color] LIKE case when @Color is Null then [Color] else @Color end)

    AND ([ListPrice] >= case when IsNull(@ListPriceMin,0) = 0 then [ListPrice] else @ListPriceMin end)

    AND ([ListPrice] <= case when IsNull(@ListPriceMax,0) = 0 then [ListPrice] else @ListPriceMax end)

    AND (ModifiedDate >= case when @ModifiedDateMin is Null then ModifiedDate else @ModifiedDateMin end)

    AND (ModifiedDate <= case when @ModifiedDateMax is Null then ModifiedDate else @ModifiedDateMax end)

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]