how to write 开发者_C百科an sql query to do: if the parameter is empty then it display all records, but if the parameter is not empty, it display the records for this value?
thank you
SELECT *
FROM YourTable
WHERE (YourColumn = @Param OR @Param IS NULL)
However, this may not always be an optimal approach. See: Catch-all queries for one discussion.
Another option:
WHERE Column1 = COALESCE(@Param, Column1)
精彩评论