看看這樣的事情。
我會注意到,雖然你錯過了開幕行。像101,空,200,5
DECLARE @Table TABLE(
item_no INT,
item_amount_from FLOAT,
item_amount_to FLOAT,
price FLOAT
)
INSERT INTO @Table SELECT 101,200,300,10
INSERT INTO @Table SELECT 101,300,400,20
INSERT INTO @Table SELECT 101,400,500,30
INSERT INTO @Table SELECT 101,500,null,40
DECLARE @Amount FLOAT,
@ItemNO INT
SELECT @Amount = 510,
@ItemNO = 101
SELECT *
FROM @Table
WHERE item_no = @ItemNO
AND (
((item_amount_from <= @Amount AND item_amount_to > @Amount))
OR (@Amount >= item_amount_from AND item_amount_to IS NULL)
OR (@Amount <= item_amount_to AND item_amount_from IS NULL)
)
但它在存儲過程而言,不能我有一些直接查詢 – NoviceToDotNet 2010-11-05 07:06:40
什麼的isNull在這個 – NoviceToDotNet 2010-11-05 07:09:58
的IS空值cncept將是檢查的無界(500個),所以如果金額爲510. – 2010-11-05 08:07:06