开发者

Search in sql database

开发者 https://www.devze.com 2023-03-20 21:19 出处:网络
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?

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

精彩评论

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