VB6语法问题

发布于 2024-10-31 11:17:56 字数 122 浏览 0 评论 0原文

谁能告诉我这个星号(*)是做什么用的。 ...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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

看春风乍起 2024-11-07 11:17:56

LIKE 条件允许您在 SQL 语句的 where 子句中使用通配符。这允许您执行模式匹配。 LIKE 条件可用于任何有效的 SQL 语句 - 选择、插入、更新或删除。

您可以选择的模式有:

% allows you to match any string of any length (including zero length)

_ allows you to match on a single character

接下来,让我们解释 _ 通配符的工作原理。请记住,_ 仅查找一个字符。

例如,

SELECT * FROM suppliers
WHERE supplier_name like 'Sm_th';

此 SQL 语句将返回名称长度为 5 个字符的所有供应商,其中前两个字符为“Sm”,最后两个字符为“th”。例如,它可以返回名称为“Smith”、“Smyth”、“Smath”、“Smeth”等的供应商。

这是另一个例子,

SELECT * FROM suppliers
WHERE account_number like '12317_';

同样的方式,你可以使用星号(*)而不是(%),

我希望它对你有帮助

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:

% allows you to match any string of any length (including zero length)

_ allows you to match on a single character

Next, let's explain how the _ wildcard works. Remember that the _ is looking for only one character.

For example,

SELECT * FROM suppliers
WHERE supplier_name like 'Sm_th';

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,

SELECT * FROM suppliers
WHERE account_number like '12317_';

The same way u can use asterisk (*) instead of (%)

I hope its help to you

北斗星光 2024-11-07 11:17:56

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 testabc

The 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 %

蓝海似她心 2024-11-07 11:17:56

这更像是一个 SQL 语法问题,而不是 VB6 问题。 :-)

你还没有提到它正在与哪个数据库通信(我假设它正在与数据库通信)。星号在 SQL(或 VB6 字符串)中通常并不特殊,因此查询将查找 empid 与您的 idNumber 中的任何内容类似用星号表示。可能不是预期的那样。如果您将其替换为 %,则您将查找以 idNumber开头的任何 empid > 变量。如果列是数字,则在比较之前将其转换为文本。

例如,如果 idNumber 包含 100,并且数据库中有 empid 值,其值为 10 >、100100010000,查询将匹配除第一个之外的所有查询,因为“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 being like whatever's in your idNumber followed by an asterisk. Probably not what was intended. If you replace it with a %, you'll be looking for any empid that starts with whatever's in your idNumber variable. If the column is numeric, it will be converted to text before the comparison.

So for instance, if idNumber contains 100, say, and there are empid values in the database with the values 10, 100, 1000, and 10000, the query would match all but the first of those, since "100", "1000", and "10000" are all like "100%".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文