Trying to query AD on a linked server error message is 7321 Trying to query AD on a linked server error message is 7321 error occurred while preparing the query.  Any suggestions?

Select Name, EmployeeID, Mail, SamAccountName
FROM OPENQUERY(ADSI, 'SELECT Name, EmployeeID, Mail
FROM ''LDAP://DC=mydomain,DC=com''
WHERE  objectClass=''user'' AND EmployeeID &gt; 0 and SamAccountName = ''f.bower''')
At a minimum, in the outer query you want SamAccountName which you are using within the openquery as a filter but do not have in your select list there.

Whether that's the root issue or just a byproduct of you doctoring this up for the site remains to be seen.

Select Name, EmployeeID, Mail, SamAccountName
FROM OPENQUERY(ADSI, 'SELECT Name, EmployeeID, Mail, SamAccountName
FROM ''LDAP://DC=mydomain,DC=com''
WHERE  objectClass=''user'' AND EmployeeID &gt; 0 and SamAccountName = ''f.bower''')