VB6语法问题
谁能告诉我这个星号(*)是做什么用的。 ...tblpersonal where empid like '" & idNumber & "*'"
。如果我将其替换为百分号(%),结果会怎样?
Can anyone tell me what this Asterisk(*) is for. ...tblpersonal where empid like '" & idNumber & "*'"
. What if I replace it with Percent sign(%), what would be the outcome?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
LIKE 条件允许您在 SQL 语句的 where 子句中使用通配符。这允许您执行模式匹配。 LIKE 条件可用于任何有效的 SQL 语句 - 选择、插入、更新或删除。
您可以选择的模式有:
接下来,让我们解释 _ 通配符的工作原理。请记住,_ 仅查找一个字符。
例如,
此 SQL 语句将返回名称长度为 5 个字符的所有供应商,其中前两个字符为“Sm”,最后两个字符为“th”。例如,它可以返回名称为“Smith”、“Smyth”、“Smath”、“Smeth”等的供应商。
这是另一个例子,
同样的方式,你可以使用星号(*)而不是(%),
我希望它对你有帮助
The LIKE condition allows you to use wildcards in the where clause of an SQL statement. This allows you to perform pattern matching. The LIKE condition can be used in any valid SQL statement - select, insert, update, or delete.
The patterns that you can choose from are:
Next, let's explain how the _ wildcard works. Remember that the _ is looking for only one character.
For example,
This SQL statement would return all suppliers whose name is 5 characters long, where the first two characters is 'Sm' and the last two characters is 'th'. For example, it could return suppliers whose name is 'Smith', 'Smyth', 'Smath', 'Smeth', etc.
Here is another example,
The same way u can use asterisk (*) instead of (%)
I hope its help to you
SQL 中的百分号 (%) 表示“匹配此处任意数量的字符”。例如
LIKE '%test'
将匹配 abctest,LIKE 'test%'
将匹配 testabc星号字符看起来会匹配文字 *,例如匹配所有 empid 结尾带有星号(取决于 SQL 版本 - 见下文)
编辑:请参阅 Microsoft Jet 通配符:星号还是百分号? 有关 * 与 % 的更深入答案
The Percent (%) sign in SQL says "match any number of characters here". E.g.
LIKE '%test'
will match abctest,LIKE 'test%'
will match testabcThe Asterisk character looks like it'll match a literal *, e.g. matching all empids ending with an asterisk (depending on the version of SQL - see below)
EDIT: See Microsoft Jet wildcards: asterisk or percentage sign? for a more in depth answer on * vs %
这更像是一个 SQL 语法问题,而不是 VB6 问题。 :-)
你还没有提到它正在与哪个数据库通信(我假设它正在与数据库通信)。星号在 SQL(或 VB6 字符串)中通常并不特殊,因此查询将查找
empid
与您的idNumber
中的任何内容类似用星号表示。可能不是预期的那样。如果您将其替换为%
,则您将查找以idNumber
开头的任何empid
> 变量。如果列是数字,则在比较之前将其转换为文本。例如,如果
idNumber
包含100
,并且数据库中有empid
值,其值为10
>、100
、1000
和10000
,查询将匹配除第一个之外的所有查询,因为“100”、“1000”、和“10000”都类似于“100%”。This is much more a SQL syntax question than a VB6 one. :-)
You haven't mentioned what database this is talking to (I assume it's talking to a DB). The asterisk is not generally special in SQL (or VB6 strings), and so that query will look for
empid
beinglike
whatever's in youridNumber
followed by an asterisk. Probably not what was intended. If you replace it with a%
, you'll be looking for anyempid
that starts with whatever's in youridNumber
variable. If the column is numeric, it will be converted to text before the comparison.So for instance, if
idNumber
contains100
, say, and there areempid
values in the database with the values10
,100
,1000
, and10000
, the query would match all but the first of those, since "100", "1000", and "10000" are alllike
"100%".