Results 1 to 11 of 11
  1. #1
    BassMan50 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    New Mexico
    Posts
    6

    NewtoAccess Query Problem

    Below is the SQL statement of a query. No matter what I do I still get all records back when I run this query.



    SELECT T_Sponsor.T_S_LastName, T_Sponsor.T_S_FirstName, T_Sponsor.T_S_MI, T_Sponsor.T_S_SSN, T_Sponsor.T_S_Gender, T_Sponsor.T_S_DOB, T_Sponsor.T_S_PCM, T_MedInfo.T_M_DateRevPCM
    FROM T_Sponsor INNER JOIN T_MedInfo ON T_Sponsor.T_S_SponsorId = T_MedInfo.T_M_SponsorId
    WHERE (([T_M_DateRevPCM]>7));

    Any ideas?

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Welcome to the forum!

    What do you want the query to return?

    What is this field? T_M_DateRevPCM
    What type of data does it hold? What is the field's datatype?

  3. #3
    BassMan50 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    New Mexico
    Posts
    6

    thanks for the reply...

    I want the query to return records > 7 days of the current date. That column is the date a physician has reviewed the initial medical record. The data type is date, ( short date format).

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You need to determine the difference in the dates using the datediff() and the date() function and apply that in the WHERE clause of the query:

    WHERE datediff("d",T_M_DateRevPCM,date())>7;

  5. #5
    BassMan50 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    New Mexico
    Posts
    6
    Thanks, that worked! Is there a book you could recommend to learn the SQL statements for access?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847

  7. #7
    BassMan50 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    New Mexico
    Posts
    6
    Thanks to both of you for the help!!

  8. #8
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome!

  9. #9
    BassMan50 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    New Mexico
    Posts
    6
    It is possible to have the query include null values for [T_MedInfo.T_M_DateRevPCM] as well as when a date is entered in that field?

    WHERE DateDiff
    ("d",T_MedInfo.T_M_DateSignINP,T_MedInfo.T_M_DateR evPCM)>7;

  10. #10
    William McKinley is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    59
    Quote Originally Posted by BassMan50 View Post
    It is possible to have the query include null values for [T_MedInfo.T_M_DateRevPCM] as well as when a date is entered in that field?

    You could add another criteria to your where clause

    Code:
    WHERE DateDiff 
    ("d",T_MedInfo.T_M_DateSignINP,T_MedInfo.T_M_DateRevPCM)>7 OR [T_MedInfo.T_M_DateRevPCM] Is Null;

  11. #11
    BassMan50 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    New Mexico
    Posts
    6
    Thanks William, it works. I was trying to add another criteria and could not get the syntax right. I'm glad I joined this forum, you guys rock!!

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

Similar Threads

  1. Query problem with c#
    By udigold1 in forum Queries
    Replies: 1
    Last Post: 12-19-2010, 08:34 PM
  2. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 AM
  3. Problem with query
    By maxx3 in forum Queries
    Replies: 8
    Last Post: 06-08-2009, 11:58 AM
  4. Top 25 query problem
    By tmcrouse in forum Queries
    Replies: 3
    Last Post: 05-07-2009, 09:02 AM
  5. Problem in Query
    By Bruno Trindade in forum Queries
    Replies: 4
    Last Post: 03-28-2009, 04:10 PM

Tags for this Thread

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