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.
| 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 recordswhere record_date >'2008-08-07'but, if I try:SELECT DISTINCT company FROM recordswhere 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 OptimizerTG |
 |
|
|
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. |
 |
|
|
|
|
|