Solved

Dateadd error when querying between two dates.

Posted on 2009-07-07
2
167 Views
Last Modified: 2012-05-07
SELECT     lngPatientid
FROM         tblHPNRT
HAVING      (MAX(dtmcreated) > DATEADD([month], - 6, dtmcreated))


I am getting an error when I try to query to see if an id show up 6 months prior to the last date added.   Please can you tell me what is wrong with my query.  Thanks
0
Comment
Question by:running32
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
Comment Utility
SELECT     lngPatientid
FROM         tblHPNRT
GROUP BY lngPatientid
HAVING      (MAX(dtmcreated) > DATEADD([month], - 6, dtmcreated))
0
 
LVL 40

Expert Comment

by:mrjoltcola
Comment Utility
You could also write as:

SELECT DISTINCT lngPatientid
FROM         tblHPNRT
WHERE dtmcreated > DATEADD([month], - 6, dtmcreated)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now