Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Find clients w/o recent records(tried FAQ+Search )

Author  Topic 

speakandspell
Starting Member

2 Posts

Posted - 2009-08-07 : 13:44:38
Hi all- New to SQL and brand new to the forum, so hi!
Our company has clients ("company") that orders records ("record_date"). I want to pull up a list of all clients who haven't ordered records in the last year.

I can pull up all clients who HAVE ordered records recently by:

SELECT DISTINCT company FROM records
where record_date >'2008-08-07'


but, if I try:

SELECT DISTINCT company FROM records
where record_date <'2008-08-07'

it gives me all the clients who have ordered records before 2008-08-08, including clients who are current.

Thanks in advance, hopefully after a while i can be a contributor, not just an asker.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-08-07 : 13:48:28
select company, max(record_date) maxRD from records group by company having max(record_date) < dateadd(year, -1, getdate())

Be One with the Optimizer
TG
Go to Top of Page

speakandspell
Starting Member

2 Posts

Posted - 2009-08-07 : 13:55:09
TG- You are a lifesaver, I was going about it totally different and would have never figured that out.

Thanks again for a lightning-fast response.
Go to Top of Page
   

- Advertisement -