Solved

Dateadd error when querying between two dates.

Posted on 2009-07-07
2
168 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

'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 …
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

18 Experts available now in Live!

Get 1:1 Help Now