我有下表COMPI,PRO,COMPRADO和下一个SQL查询和参数fecha1,fecha2,comprador
查询中的返回语法错误
这段代码有什么问题? (是ADODB VBA EXCEL MACRO的字符串sql)
SELECT DISTINCT compi.DOCCOMPI,compi.FECHCOMPI,compi.MACOD,compi.MANOM,compi.MAREF,
compi.MADIM,compi.CPCOMPI,compi.MAUNI,pro.PRONOM,comprado.NOMBRE
FROM comprado
INNER JOIN compi ON comprado.CODIGO=compi.COMPRADOR
INNERJOIN pro ON compi.NITCOMPI=pro.PRONIT
WHERE compi.TEMPCOMPI='h' AND
compi.FECHCOMPI BETWEEN " & "#" & fecha1 & "#" &
"AND " & "#" & fecha2 & "#" & " AND
comprado.CODIGO=" & comprador & "
答案 0 :(得分:0)
尝试删除INNER JOIN之间的空格,并使用单引号作为字符串而不是双引号:
SELECT DISTINCT compi.DOCCOMPI,compi.FECHCOMPI,compi.MACOD,compi.MANOM,compi.MAREF,
compi.MADIM,compi.CPCOMPI,compi.MAUNI,pro.PRONOM,comprado.NOMBRE
FROM comprado
INNER JOIN compi ON comprado.CODIGO=compi.COMPRADOR
INNER JOIN pro ON compi.NITCOMPI=pro.PRONIT
WHERE compi.TEMPCOMPI='h' AND
compi.FECHCOMPI BETWEEN ' & "#" & fecha1 & "#" &
' AND ' & "#" & fecha2 & "#" & ' AND
comprado.CODIGO=' & comprador & '