开发者

Search in sql database

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜