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 |
|
Lionheart
Starting Member
41 Posts |
Posted - 2009-03-02 : 11:28:41
|
| I have a table which contains information such as the following: -ID Date1 2009-2-241 2009-2-251 2009-2-262 2009-1-212 2009-2-242 2009-2-283 2008-12-293 2009-1-2etc.This records when another table linked to ID changes for thousands of ID's. What I need to do is select the earliest date for each ID and the ID for the last 30 days only. How do I go about doing this?ThxLH |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-03-02 : 11:31:15
|
| select ID, min(Date) from table where date > dateadd(dd,0,datediff(dd,0,dateadd(dd,-30,getdate())))group by ID |
 |
|
|
Lionheart
Starting Member
41 Posts |
Posted - 2009-03-02 : 11:37:02
|
| Thank you very much. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-02 : 12:42:53
|
quote: Originally posted by RickD select ID, min(Date) from table where date > dateadd(dd,0,datediff(dd,0,dateadd(dd,-30,getdate())))group by ID
the line in blue can be simplified asdateadd(dd,datediff(dd,0,getdate())-30,0) |
 |
|
|
|
|
|
|
|