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 |
TwisteD16
Starting Member
4 Posts |
Posted - 2011-12-07 : 02:31:07
|
Hi,I'm trying to sort the last sales of each store. Let's say I have a data set like this:StoreNo TransactionDate5 2011-12-07 00:59:32.7504 2011-12-07 00:56:85.7505 2011-12-07 00:30:32.7501 2011-12-07 00:55:32.750And result would look like this:StoreNo LastTransaction5 2011-12-07 00:59:32.7504 2011-12-07 00:56:85.7501 2011-12-07 00:55:32.750This could be achieved easily using Rank() in sqlserver 2005 but I need it to work on 2000. Anyone who could help me? |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-07 : 02:33:49
|
[code]select StoreNo, max(TransactionDate)from salesgroup by StoreNo[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
TwisteD16
Starting Member
4 Posts |
Posted - 2011-12-07 : 03:02:55
|
Thanks. You helped my out alot. I am now able to use this to join into other tables. :) |
|
|
TwisteD16
Starting Member
4 Posts |
Posted - 2011-12-07 : 03:19:54
|
Sorry about this. It seems like this doesn't work if I include other fields. here's the scenarioStoreNo TransactionDate accntno5 2011-12-07 00:59:32.750 34 2011-12-07 00:56:85.750 15 2011-12-07 00:30:32.750 31 2011-12-07 00:55:32.750 2And result would look like this:StoreNo LastTransaction acctno5 2011-12-07 00:59:32.750 34 2011-12-07 00:56:85.750 11 2011-12-07 00:55:32.750 2Anyone please? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-07 : 04:04:24
|
[code]select StoreNo, max(TransactionDate), acctnofrom salesgroup by StoreNo, acctno[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
TwisteD16
Starting Member
4 Posts |
Posted - 2011-12-07 : 04:12:00
|
Thanks. Got my statements running. :) |
|
|
|
|
|