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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Date selection

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-10-07 : 05:48:42
I have a table with structure

diary
-----

clientid date code
-------- ---- ----
10122 2009-04-03 3


How can I return the clientid where the max date is greater than 6 months from today's date please?

sanoj_av
Posting Yak Master

118 Posts

Posted - 2009-10-07 : 05:55:29
Select
clientid
group by
clientid
having
max(date) > dateadd(M,6,getdate())
Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-10-07 : 06:19:11
Thanks for the reply.

I made an error. I should have asked

'How can I return the clientid where the max date is older than 6 months prior to today's date please?'

My apologies

Go to Top of Page

sanoj_av
Posting Yak Master

118 Posts

Posted - 2009-10-07 : 06:22:57
Select
clientid
group by
clientid
having
max(date) < dateadd(M,-6,getdate())
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2009-10-07 : 06:32:55
[code]Select clientid from tblFoo
group by clientid
having max(dateadd(day, datediff(day, 0, dateColumn), 0)) < dateadd(month, -6, dateadd(day, datediff(day, 0, getdate()), 0))[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -