Solved

Dateadd error when querying between two dates.

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get Duration of last Status Update 4 35
How to join on ID, with prefix? 15 59
Dcount using a date in a table compared to today's date 3 30
performance query 4 24
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

778 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