Syntax error (missing statement)

I am not a trained programmer, so trying to do this is difficult. I am getting the above error with this SQL code and I can not understand the reason. Please inform.

SELECT a.agentname as 'Salesforce AgentName', a.loannumber, ag.agentname as 'portal agentname' from salesforce a inner join portal b ON a.loannumber = b.loannumber left join agents ag ON b.agentid = ag.agentid where a.agentname <> ag.agentname 
+4
source share
2 answers

Guessing bit ( based here )

 SELECT a.agentname AS 'Salesforce AgentName', a.loannumber, ag.agentname AS 'portal agentname' FROM ((salesforce as a ) INNER JOIN portal as b ON a.loannumber = b.loannumber) LEFT JOIN agents ag ON b.agentid = ag.agentid WHERE a.agentname <> ag.agentname 

BTW is usually a mistake to refer to outer columns of a joined table in a WHERE if you do not consider the possibility that they are NULL

+2
source

Access to the db engine has strict parenthesis requirements when the SELECT statement contains more than one join. I suggest you start with a simplified version of the query (drop the list of fields and the WHERE clause) so that you can focus on the correct connection.

 SELECT * FROM (salesforce AS a INNER JOIN portal AS b ON a.loannumber = b.loannumber) LEFT JOIN agents AS ag ON b.agentid = ag.agentid; 

Assuming this version works, try the following:

 SELECT a.agentname AS [Salesforce AgentName], a.loannumber, ag.agentname AS [portal agentname] FROM (salesforce AS a INNER JOIN portal AS b ON a.loannumber = b.loannumber) LEFT JOIN agents AS ag ON b.agentid = ag.agentid WHERE a.agentname <> ag.agentname; 

Notice that I enclose aliases for column names with square brackets instead of single quotes. Single quotes will not cause an error, but they will be included in the column heading ... that I doubt you want.

You will do a favor by creating Access queries in the Access query designer. This makes it difficult to create a query with syntax that the db engine will not accept.

Change If the purpose of this query is to compare agent name values ​​from Salesforce tables and agents, you might want to try this as a WHERE clause:

 WHERE a.agentname <> ag.agentname OR ag.agentname Is Null; 
+1
source

Source: https://habr.com/ru/post/1392143/


All Articles