0
@fromValue FLOAT; @toValue FLOAT;
SELECT *
 FROM INVOICE
 WHERE TOTAL > @fromValue and TOTAL < @toValue

我有一个包含 TOTAL 列的 INVOICE 表。我想在这样的组合框中选择 3 个条件:

  • 总计 < 100 --> (@fromValue = 0 ; @toValue = 100)
  • 100 < 总计 < 200 --> (@fromValue = 100 ; @toValue = 200)
  • 总计 > 500 --> (@fromValue =500;@toValue ???)
4

3 回答 3

1

您可以传递如下变量:

DECLARE @fromValue DECIMAL(18,4), @toValue DECIMAL(18,4);

SET @fromValue = 500 ; -- depending on initial value
--SET @toValue = NULL;

SELECT *
FROM INVOICE
WHERE TOTAL BETWEEN ISNULL(@fromVALUE,0) AND ISNULL(@toValue,9999999);
于 2017-10-29T07:33:30.567 回答
0

我无法想象或理解您究竟需要什么,但是如果您想传递两(2)个值并使用它,那么:

SELECT *
FROM INVOICE
WHERE TOTAL BETWEEN @fromValue AND @toValue;
于 2017-10-29T08:11:09.830 回答
0

我一定错过了什么,因为它看起来太简单了?

SELECT 
    *
FROM
    Invoice
WHERE
    Total < 100 OR Total Between 100 and 200 OR Total > 500
于 2017-10-29T07:39:58.913 回答