gpt4 book ai didi

c# - SQL Where 子句条件

转载 作者:行者123 更新时间:2023-11-30 13:15:10 26 4
gpt4 key购买 nike

在 sql where 子句中;如果 pv.SalePricenull,我想使用 pv.Price。我该怎么做?

WHERE    
@FilterRangePriceValueMin < pv.SalePrice OR pv.SalePrice is null
AND (@FilterRangePriceValueMax > pv.SalePrice OR pv.SalePrice is null)

最佳答案

您可以使用 COALESCE函数按顺序尝试 NULL 的项目,然后取第一个非空的进行比较。您还可以使用 BETWEEN 来避免两次调用:

WHERE
COALESCE(pv.SalePrice, pv.Price)
BETWEEN @FilterRangePriceValueMin AND @FilterRangePriceValueMax

关于c# - SQL Where 子句条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14123624/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com