简体   繁体   English

Access和VB6查询以获取基于一系列数字的值

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

Am writing a query to get commission from a table tblcommssion but this depends on the amount entered in a text box. 我正在编写查询以从表tblcommssion获取佣金,但这取决于在文本框中输入的数量。

Eg 例如

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

my query is 我的查询是

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

But it fetches wrong the commission, ie one that does not correspond with the row eg when I enter 4200, I expect commission to be 125 since 4200 lies between 2501 and 5000. 但是它获取错误的佣金,即与行不对应的佣金,例如,当我输入4200时,我期望佣金为125,因为4200位于2501和5000之间。

Where did I go wrong? 我哪里做错了?

You are comparing strings and numbers. 您正在比较字符串和数字。 This is dangerous, because the values are compared as strings . 这很危险,因为将值作为字符串进行比较。 Start by removing the quotes around the values: 首先删除值周围的引号:

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

This assumes that min_tier and max_tier are numbers. 假设min_tiermax_tier是数字。 If they are strings, you also need to fix their types in the table. 如果它们是字符串,则还需要在表中修复其类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM