gpt4 book ai didi

sql - VBA SQL查询字符串,支持多少?

转载 作者:行者123 更新时间:2023-12-04 21:24:31 26 4
gpt4 key购买 nike

仍在为一个项目进行查询,我的合作伙伴设法提出了一个漂亮的 SQL 语句,运行时会产生奇迹,但在 VBA 中似乎不起作用,这让我质疑 VBA 支持多少 SQL 语句

这是我的工作伙伴发起的原始查询,在 SQL 中运行查询时效果很好

SELECT
crm_clients.`id`,
crm_clients.`national_insurance`,
crm_clients.`total_hmrc`,
(SELECT
crm_crmuseractions.title
FROM
dev_pfands.`crm_crmuseractions`
WHERE crm_crmuseractions.`id` = crm_clients.`status`) AS `status`
FROM
dev_pfands.`crm_clients`
INNER JOIN crm_client_cheques
ON crm_clients.id = crm_client_cheques.`client_id`
INNER JOIN dev_pfands.`crm_payments`
ON crm_clients.id = crm_payments.`client_id`
INNER JOIN dev_pfands.`crm_self_assesments`
ON crm_clients.id = crm_self_assesments.`client_id`
WHERE crm_clients.`status` = 9
OR crm_clients.`status` = 8
OR crm_clients.`status` = 7
OR crm_clients.`national_insurance` != ''
OR crm_clients.`id` != ''

我知道 VBA 喜欢 SQL 的结构有点不同,所以我对其进行了调整,这可能是错误的,所以如果我需要学习,请随意烧我。
sql = "SELECT crm_clients.id, crm_clients.national_insurance, crm_clients.total_hmrc _
(SELECT _
crm_crmuseractions.title _
FROM _
crm_crmuseractions _
WHERE crm_crmuseractions.id = crm_clients.status ) AS 'status _
FROM _
crm_clients _
INNER JOIN crm_client_cheques _
ON crm_clients.id = crm_client_cheques.client_id _
INNER JOIN crm_payments _
ON crm_clients.id = crm_payments.client_id _
INNER JOIN crm_self_assesments.client_id _
WHERE crm_clients.status = 9 _
OR crm_clients.status = 8 _
OR crm_clients.status = 7 _
OR crm_clients.national_insurance != '' _
OR crm_clients.id != '' "

如果我错过了某些东西,请提前道歉,但除了简单的选择或插入/删除和更新 SQL 的其他一些功能(如连接等)之外的任何其他功能似乎在 VBA 中对我不起作用

如果有人知道我哪里出错了,那就太好了,如果我做得很好,而且它不支持的功能甚至解释为什么会很好,这样我就可以将它与我认为它有效的工作 friend 联系起来。

感谢先进的家伙。

最佳答案

Dim query As String

query = "SELECT " & _
"crm_clients.id, " & _
"crm_clients.national_insurance, " & _
"crm_clients.total_hmrc, " & _
"(SELECT " & _
" crm_crmuseractions.Title " & _
"FROM " & _
" dev_pfands.crm_crmuseractions " & _
"WHERE crm_crmuseractions.`id` = crm_clients.status) AS 'status' " & _
"FROM " & _
"dev_pfands.crm_clients " & _
"INNER JOIN crm_client_cheques " & _
" ON crm_clients.id = crm_client_cheques.client_id " & _
"INNER JOIN dev_pfands.crm_payments " & _
" ON crm_clients.id = crm_payments.client_id " & _
"INNER JOIN dev_pfands.crm_self_assesments " & _
" ON crm_clients.id = crm_self_assesments.client_id " & _
"WHERE crm_clients.status = 9 " & _
"OR crm_clients.status = 8 " & _
"OR crm_clients.status = 7 " & _
"OR crm_clients.national_insurance != '' " & _
"OR crm_clients.id != ''"

关于sql - VBA SQL查询字符串,支持多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25608405/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com