Search code examples
sqlms-accesshaving

ms access query having


I have the following part from a big SQL which is working fine:

HAVING (((Format([AppointmentDate],0))<>[AppointmentControlDate]))) AS ControlDate 

I am trying to add OR in my SQL but I am getting error.

Error 3122. You tried to execute a query that does not include the specified expression 
<name> as part of an aggregate function.

The SQL looks like this:

HAVING (((Format([AppointmentDate],0))<>[AppointmentControlDate]))) OR (((AppointmentControlDate)=Format$(Date(),"00"))) AS ControlDate 

Thank you.

If someone want all the SQL, please inform me to edit my post.


Solution

  • You shouldn't have an AS... in a HAVING statement.

    You can remove AS ControlDate, and also almsot all of the brackets are unnecessary.

    Try this:

    HAVING Format(AppointmentDate,0)<>AppointmentControlDate
    

    If you're still having problems, you edit your question to add the entire SQL statement and I will take another look.