Results 1 to 8 of 8
  1. #1
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25

    Adding an additional WHERE clause

    I am using the following code which works fine in a query:

    SELECT PEPERSON.PERSONNEL_NO, PEPERSON.SURNAME, PEPERSON.CENTRE, [Input Week Number] AS WEEK_NO, PEPERSON.DATE_LEFT
    FROM PEPERSON


    WHERE (((PEPERSON.CENTRE)>"0") AND ((PEPERSON.DATE_LEFT) Is Null) AND ((Exists (SELECT JCBATCH.PERSONNEL_NO FROM JCBATCH
    WHERE JCBATCH.COMPANY = PEPERSON.COMPANY AND JCBATCH.WEEK_NO = [Input Week Number] AND JCBATCH.PERSONNEL_NO = PEPERSON.PERSONNEL_NO AND JCBATCH.ORIG_ADJUST = "Original" AND JCBATCH.UPDATED IN ("Held", "Ready", "Updated")))=False) AND ((PEPERSON.USE_IN_TB)=1) AND ((PEPERSON.COMPANY)="PFC1"))
    ORDER BY PEPERSON.PERSONNEL_NO;

    I need to be able to insert the following additional WHERE statement into my code (note that I am already using PEPERSON.DATE_LEFT to filter on all values that are blank):

    OR PEPERSON.DATE_LEFT > MAX(JCBATCH.WEEK_END_DATE)

    I have tried to put the above into my code, but so far failing miserably. Does anyone know where I can successfully insert the above statement t get it to work successfully?

    Any suggestion would be greatly received - many thanks.

    Many thanks

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    try changing this:
    Code:
    MAX(JCBATCH.WEEK_END_DATE)
    to this:
    Code:
    DMAX(JCBATCH.WEEK_END_DATE)

  3. #3
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25
    Quote Originally Posted by ajetrumpet View Post
    try changing this:
    Code:
    MAX(JCBATCH.WEEK_END_DATE)
    to this:
    Code:
    DMAX(JCBATCH.WEEK_END_DATE)
    Many thanks for this.

    Do you know where I put this into my code?

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    as I said, SUBSTITUTE it in for the MAX() function you have now. make sense?

  5. #5
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25
    Quote Originally Posted by ajetrumpet View Post
    as I said, SUBSTITUTE it in for the MAX() function you have now. make sense?
    Apologies, but I dont currently have this additional WHERE statement inserted into my code yet and my original question was where do I insert (apologies, but I am a novice and learning all the time with this).

    Many thanks.

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    SELECT PEPERSON.PERSONNEL_NO, PEPERSON.SURNAME, PEPERSON.CENTRE, [Input Week Number] AS WEEK_NO, PEPERSON.DATE_LEFT
    FROM PEPERSON
    WHERE (((PEPERSON.CENTRE)>"0") AND ((PEPERSON.DATE_LEFT) Is Null) AND ((Exists (SELECT JCBATCH.PERSONNEL_NO FROM JCBATCH
    WHERE JCBATCH.COMPANY = PEPERSON.COMPANY AND JCBATCH.WEEK_NO = [Input Week Number] AND JCBATCH.PERSONNEL_NO = PEPERSON.PERSONNEL_NO AND JCBATCH.ORIG_ADJUST = "Original" AND JCBATCH.UPDATED IN ("Held", "Ready", "Updated")))=False) AND ((PEPERSON.USE_IN_TB)=1) AND ((PEPERSON.COMPANY)="PFC1"))

    OR PEPERSON.DATE_LEFT > DMAX(JCBATCH.WEEK_END_DATE)

    ORDER BY PEPERSON.PERSONNEL_NO;

  7. #7
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25
    Quote Originally Posted by ajetrumpet View Post
    SELECT PEPERSON.PERSONNEL_NO, PEPERSON.SURNAME, PEPERSON.CENTRE, [Input Week Number] AS WEEK_NO, PEPERSON.DATE_LEFT
    FROM PEPERSON
    WHERE (((PEPERSON.CENTRE)>"0") AND ((PEPERSON.DATE_LEFT) Is Null) AND ((Exists (SELECT JCBATCH.PERSONNEL_NO FROM JCBATCH
    WHERE JCBATCH.COMPANY = PEPERSON.COMPANY AND JCBATCH.WEEK_NO = [Input Week Number] AND JCBATCH.PERSONNEL_NO = PEPERSON.PERSONNEL_NO AND JCBATCH.ORIG_ADJUST = "Original" AND JCBATCH.UPDATED IN ("Held", "Ready", "Updated")))=False) AND ((PEPERSON.USE_IN_TB)=1) AND ((PEPERSON.COMPANY)="PFC1"))

    OR PEPERSON.DATE_LEFT > DMAX(JCBATCH.WEEK_END_DATE)

    ORDER BY PEPERSON.PERSONNEL_NO;
    Thanks for you reply but doing this results in the following error:

    Cannot have aggregate function in WHERE clause.

    Any other ideas?

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    try changing the word 'WHERE' to 'HAVING'. Aside from that, I can't help much more because your data is specific and I'd have to see the database with instructions on what the resulting dataset would have to look like.

    good luck sir!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Where clause syntax
    By stupesek in forum Reports
    Replies: 7
    Last Post: 09-03-2010, 02:26 PM
  2. update in where clause
    By mikensu in forum Access
    Replies: 0
    Last Post: 03-16-2009, 07:19 AM
  3. Additional params for ANY query
    By dnagir in forum Access
    Replies: 0
    Last Post: 01-21-2009, 10:05 PM
  4. IIF clause
    By Peljo in forum Queries
    Replies: 2
    Last Post: 02-05-2008, 11:22 AM
  5. Help on WHERE clause
    By QBCM in forum Programming
    Replies: 1
    Last Post: 12-19-2005, 08:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums