我试图运行下面的查询,但它在'unionselect'附近显示错误的错误语法有人可以帮忙吗?
strsql = "select distinct a.LOCID,locnum,locname,streetname,city,county,statecode,state,peril,SITEDEDAMT,SITELIMAMT,COMBINEDDEDAMT,COMBINEDLIMAMT from eqdet a inner join loccvg b on a.LOCID=b.locid inner join loc c on b.LOCID=c.LOCID where PERIL=1" & _
"union" & _
"select distinct a.LOCID,locnum,locname,streetname,city,county,statecode,state,peril,SITEDEDAMT,SITELIMAMT,COMBINEDDEDAMT,COMBINEDLIMAMT from hudet a inner join loccvg b on a.LOCID=b.locid inner join loc c on b.LOCID=c.LOCID where peril=2" & _
"union" & _
"select distinct a.LOCID,locnum,locname,streetname,city,county,statecode,state,peril,SITEDEDAMT,SITELIMAMT,COMBINEDDEDAMT,COMBINEDLIMAMT from todet a inner join loccvg b on a.LOCID=b.locid inner join loc c on b.LOCID=c.LOCID where peril=3" & _
"union" & _
"select a.LOCID,locnum,locname,streetname,city,county,statecode,state,peril,SITEDEDAMT,SITELIMAMT,COMBINEDDEDAMT,COMBINEDLIMAMT from fldet a inner join loccvg b on a.LOCID=b.locid inner join loc c on b.LOCID=c.LOCID where peril=4" & _
"union" & _
"select distinct a.LOCID,locnum,locname,streetname,city,county,statecode,state,peril,SITEDEDAMT,SITELIMAMT,COMBINEDDEDAMT,COMBINEDLIMAMT from frdet a inner join loccvg b on a.LOCID=b.locid inner join loc c on b.LOCID=c.LOCID where peril=5" & _
"union" & _
"select distinct a.LOCID,locnum,locname,streetname,city,county,statecode,state,peril,SITEDEDAMT,SITELIMAMT,COMBINEDDEDAMT,COMBINEDLIMAMT from trdet a inner join loccvg b on a.LOCID=b.locid inner join loc c on b.LOCID=c.LOCID where peril=6"
答案 0 :(得分:3)
查看错误消息我怀疑您正在整理字符串以进行查询。 unionselect
应该是两个单词,由空格分隔。 (union select
)我认为在您的代码空间中缺少单独的关键字。
请参阅:
"...where PERIL=1" & _ "union" & _ "select distinct..."
将产生
...where PERIL=1unionselect distinct...
输出。正确的代码(注意联合周围的空格):
"...where PERIL=1" & _ " union " & _ "select distinct ..."