簡體   English   中英

Access和VB6查詢以獲取基於一系列數字的值

[英]Access and VB6 Query for getting a value based on a range of numbers

我正在編寫查詢以從表tblcommssion獲取佣金,但這取決於在文本框中輸入的數量。

例如

| min_tier | max_tier | commission |
|----------| ---------| ---------- |
|   500    | 2500     | 100        | 
|   2501   | 5000     | 125        | 
|   5001   | 15000    | 450        | 

我的查詢是

Select commission
from tblAgentCommission
where min_tier <= '" & Format(txtWithAmount.Text, "##0")"' and
      max_tier >= '" & Format(txtWithAmount.Text, "##0") & "'

但是它獲取錯誤的佣金,即與行不對應的佣金,例如,當我輸入4200時,我期望佣金為125,因為4200位於2501和5000之間。

我哪里做錯了?

您正在比較字符串和數字。 這很危險,因為將值作為字符串進行比較。 首先刪除值周圍的引號:

Select commission
from tblAgentCommission
where min_tier <= " & Format(txtWithAmount.Text, "##0")" and
      max_tier >= " & Format(txtWithAmount.Text, "##0");

假設min_tiermax_tier是數字。 如果它們是字符串,則還需要在表中修復其類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM