【发布时间】:2017-07-16 18:38:15
【问题描述】:
我有一个充满产品的表,之前我们将MaxPrice 和MinPrice 传递给存储过程,并选择了价格在两个值之间的产品。
但现在我想传递多个范围值,并希望选择价格在多个范围之间的产品。
假设我有一个这样的存储过程:
@PriceMin decimal(18, 4) = null,
@PriceMax decimal(18, 4) = null,
...
WHERE
product.Price > @PriceMin
AND product.Price < @PriceMax
但现在我想根据用户选择传递多个值范围,并进行如下选择:
WHERE
(product.Price > @PriceMin1 AND product.Price < @PriceMax1)
OR (product.Price > @PriceMin2 AND product.Price < @PriceMax2)
OR (product.Price > @PriceMin3 AND product.Price < @PriceMax3)
...
我该怎么做?
【问题讨论】:
-
使用动态查询构造WHERE子句
标签: sql sql-server stored-procedures