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 |
|
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2009-07-14 : 10:29:08
|
| My query needs to SELECT the 1st order of every month but I'm unsure of how.So if I have the following, I would need the orders on 03/06/09, 04/01/09, & 05/03/09:ORDER DATE | ORDER ID----------------------03/06/09 | 499903/18/09 | 738804/01/09 | 898104/18/09 | 331904/21/09 | 477305/03/09 | 8820Any idea how I can do this? Thanks. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-14 : 10:32:29
|
[code]select *from( select *, row_no = row_number() over (partition by dateadd(month, datediff(month, 0, order_date), 0) order by order_date) from yourtable) owhere row_no = 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2009-07-14 : 15:30:37
|
That did it! Thanks a million khtan! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|