VBA- TRANSFORM语句中的语法错误

时间:2022-11-11 20:38:36

I have an error in VBA, this query is operating normally as a cross tab but when I try to switch the VBA, throws me a Syntax error in TRANSFORM statement Can someone help me? Thank you.

我在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>')"

2 个解决方案

#1


2  

 "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>') "

You need spaces when joining strings otherwise your text runs together... Yours was reading "TRANSFORM..... AS USELECT..."

加入字符串时你需要空格,否则你的文字会一起运行......你们正在阅读“TRANSFORM ..... AS USELEL ...”

#2


1  

I figured out the answer is stupid, everything is fine and of course it works but a few things need to be corrected, where there is comma should stand & "" "" & and since it comes after a string to continue with & _ before that should standing space like pollID " so, looks like this `

我发现答案是愚蠢的,一切都很好,当然它有效,但有些事情需要纠正,有逗号应该站在&“”“”&因为它来自一个字符串继续&_之前应该像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>') "

#1


2  

 "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>') "

You need spaces when joining strings otherwise your text runs together... Yours was reading "TRANSFORM..... AS USELECT..."

加入字符串时你需要空格,否则你的文字会一起运行......你们正在阅读“TRANSFORM ..... AS USELEL ...”

#2


1  

I figured out the answer is stupid, everything is fine and of course it works but a few things need to be corrected, where there is comma should stand & "" "" & and since it comes after a string to continue with & _ before that should standing space like pollID " so, looks like this `

我发现答案是愚蠢的,一切都很好,当然它有效,但有些事情需要纠正,有逗号应该站在&“”“”&因为它来自一个字符串继续&_之前应该像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>') "