Solved

Dateadd error when querying between two dates.

Posted on 2009-07-07
2
170 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
ID: 24797392
SELECT     lngPatientid
FROM         tblHPNRT
GROUP BY lngPatientid
HAVING      (MAX(dtmcreated) > DATEADD([month], - 6, dtmcreated))
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24797461
You could also write as:

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

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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