带有多个逻辑运算符的 SQL 语句

发布于 2024-10-15 14:38:45 字数 345 浏览 15 评论 0原文

我需要在其中运行 SQL 查询 -current_queue不等于i01并且不以F开头 -prod_code 以 R 开头

SQL = "SELECT " & Join(theseFields, ",") & " FROM [Acct Detail$] WHERE NOT (current_queue='I01' OR LEFT(current_queue,1)='F')"

这对我来说可以删除 i01 和以 F 开头的队列,但现在如何过滤掉不以 R 开头的 prod_code ?

(这是 ADODB、VBA、Excel、Microsoft.Jet.OLEDB.4.0)

I need to run a SQL query where
-current_queue does not equal i01 and does not start with F
-prod_code starts with R

SQL = "SELECT " & Join(theseFields, ",") & " FROM [Acct Detail$] WHERE NOT (current_queue='I01' OR LEFT(current_queue,1)='F')"

That works for me to remove i01 and queues starting with F but now how do I filter out prod_code that doesn't start with R?

(this is ADODB, VBA, Excel, Microsoft.Jet.OLEDB.4.0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

星軌x 2024-10-22 14:38:45

您可能会遇到 Excel 大小写敏感的问题:

strSQL = "SELECT " & Join(theseFields, ",") & " FROM [Acct Detail$] " _
& "WHERE (Not (UCase(current_queue)='I01' " _
& "Or UCase(current_queue) Like 'F%')) " _
& " AND UCase(prod_code) Like 'R%' "

如果这是 Access,您还必须检查 Null,但这似乎不是 Excel 的问题。

You can run into case sensitivity with Excel :

strSQL = "SELECT " & Join(theseFields, ",") & " FROM [Acct Detail$] " _
& "WHERE (Not (UCase(current_queue)='I01' " _
& "Or UCase(current_queue) Like 'F%')) " _
& " AND UCase(prod_code) Like 'R%' "

If this were Access you would also have to check for Null, but it does not seem to be a problem with Excel.

惟欲睡 2024-10-22 14:38:45

没关系,我决定这样做:

SQL = "SELECT " & Join(theseFields, ",") & " FROM [Acct Detail$] WHERE NOT (current_queue='I01' OR LEFT(current_queue,1)='F' OR LEFT(prod_code,1)='C' OR LEFT(prod_code,1)='P')"

仍然好奇如何保持 prod_code 以 R 开头,但不是 i01 的 current_queue 或以 F 开头

Nevermind, I decided to go with this:

SQL = "SELECT " & Join(theseFields, ",") & " FROM [Acct Detail$] WHERE NOT (current_queue='I01' OR LEFT(current_queue,1)='F' OR LEFT(prod_code,1)='C' OR LEFT(prod_code,1)='P')"

Still curious how to keep prod_code starting with R but not current_queue of i01 or starting with F

剩余の解释 2024-10-22 14:38:45

为了清晰起见,分成几行,这些应该在一行上

SQL = "SELECT " & Join(theseFields, ",") & " FROM [Acct Detail$]
WHERE LEFT(Prod_code,1) = 'R'
AND NOT (current_queue='I01' OR LEFT(current_queue,1)='F')"

Split into lines for clarity, these should be on one single line

SQL = "SELECT " & Join(theseFields, ",") & " FROM [Acct Detail$]
WHERE LEFT(Prod_code,1) = 'R'
AND NOT (current_queue='I01' OR LEFT(current_queue,1)='F')"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文