VBA-TRANSFORM 语句中的语法错误

Posted

技术标签:

【中文标题】VBA-TRANSFORM 语句中的语法错误【英文标题】:VBA- Syntax error in TRANSFORM statement 【发布时间】:2016-12-20 11:56:48 【问题描述】:

我在 VBA 中有一个错误,此查询作为交叉表正常运行,但是当我尝试切换 VBA 时,在 TRANSFORM 语句中抛出一个语法错误有人可以帮助我吗?谢谢。

     "TRANSFORM Str(Count([Prijava].[id]))AS O, Str(Count([Prijava].[datumSmrti])) AS U" & _
     "SELECT MKB10.id, IIf([pol].[id]=1,'M','Ž') AS pol, MKB10.NazivLatinski" & _
     "FROM Pol INNER JOIN ((Opstina INNER JOIN Pacijent ON Opstina.id = Pacijent.opstinaID) INNER JOIN (MKB10 INNER JOIN Prijava ON MKB10.id = Prijava.mkb10ID) ON Pacijent.id = Prijava.pacijentID) ON Pol.id = Pacijent.polID" & _
     "GROUP BY MKB10.id, IIf([pol].[id]=1,'M','Ž'), MKB10.NazivLatinski" & _
     "ORDER BY MKB10.id" & _
     "PIVOT starosnoDoba2([starost]) In ('<1','1','2','3','4','5','6','7-9','10-14','15-19','20-29','30-39','40-49','50-59','60-69','70>')"

【问题讨论】:

【参考方案1】:
 "TRANSFORM Str(Count([Prijava].[id]))AS O, Str(Count([Prijava].[datumSmrti])) AS U " & _
     "SELECT MKB10.id, IIf([pol].[id]=1,'M','Ž') AS pol, MKB10.NazivLatinski " & _
     "FROM Pol INNER JOIN ((Opstina INNER JOIN Pacijent ON Opstina.id = Pacijent.opstinaID) INNER JOIN (MKB10 INNER JOIN Prijava ON MKB10.id = Prijava.mkb10ID) ON Pacijent.id = Prijava.pacijentID) ON Pol.id = Pacijent.polID " & _
     "GROUP BY MKB10.id, IIf([pol].[id]=1,'M','Ž'), MKB10.NazivLatinski " & _
     "ORDER BY MKB10.id " & _
     "PIVOT starosnoDoba2([starost]) In ('<1','1','2','3','4','5','6','7-9','10-14','15-19','20-29','30-39','40-49','50-59','60-69','70>') "

连接字符串时需要空格,否则您的文本会一起运行...您正在阅读 "TRANSFORM..... AS USELECT..."

【讨论】:

【参考方案2】:

我发现答案很愚蠢,一切都很好,当然它可以工作,但有一些事情需要纠正,逗号应该站在 & "" "" & 之后,因为它出现在一个字符串之后继续& _ 在此之前应该像 pollID 一样站立空间“ 所以,看起来像这样`

"TRANSFORM Str(Count([Prijava].[id]))&"" ""& Str(Count([Prijava].[datumSmrti])) " & _
"SELECT MKB10.id &"" ""& IIf([pol].[id]=1,'M','Ž') &"" ""& MKB10.NazivLatinski " & _
"FROM Pol INNER JOIN ((Opstina INNER JOIN Pacijent ON Opstina.id = Pacijent.opstinaID) INNER JOIN (MKB10 INNER JOIN Prijava ON MKB10.id = Prijava.mkb10ID) ON Pacijent.id = Prijava.pacijentID) ON Pol.id = Pacijent.polID " & _
"GROUP BY MKB10.id, IIf([pol].[id]=1,'M','Ž'), MKB10.NazivLatinski " & _
"ORDER BY MKB10.id " & _
"PIVOT starosnoDoba2([starost]) In ('<1','1','2','3','4','5','6','7-9','10-14','15-19','20-29','30-39','40-49','50-59','60-69','70>') "

【讨论】:

以上是关于VBA-TRANSFORM 语句中的语法错误的主要内容,如果未能解决你的问题,请参考以下文章

LEFT JOIN连接SQL语句在Access里面报语法错误(操作符丢失),哪位帮帮忙?

Insert Into 语句的语法错误

INSERT INTO 语句的语法错误

layui 和 require 语法怎么兼容

确定 VBA 中当前错误处理方法的语法

笑话 - 语法错误:不能在模块外使用 import 语句