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 2000 Forums
 Transact-SQL (2000)
 Rank () for date

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 TransactionDate
5 2011-12-07 00:59:32.750
4 2011-12-07 00:56:85.750
5 2011-12-07 00:30:32.750
1 2011-12-07 00:55:32.750

And result would look like this:

StoreNo LastTransaction
5 2011-12-07 00:59:32.750
4 2011-12-07 00:56:85.750
1 2011-12-07 00:55:32.750

This 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 sales
group by StoreNo
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

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. :)
Go to Top of Page

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 scenario

StoreNo TransactionDate accntno
5 2011-12-07 00:59:32.750 3
4 2011-12-07 00:56:85.750 1
5 2011-12-07 00:30:32.750 3
1 2011-12-07 00:55:32.750 2

And result would look like this:

StoreNo LastTransaction acctno
5 2011-12-07 00:59:32.750 3
4 2011-12-07 00:56:85.750 1
1 2011-12-07 00:55:32.750 2


Anyone please?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-07 : 04:04:24
[code]
select StoreNo, max(TransactionDate), acctno
from sales
group by StoreNo, acctno
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

TwisteD16
Starting Member

4 Posts

Posted - 2011-12-07 : 04:12:00
Thanks. Got my statements running. :)
Go to Top of Page
   

- Advertisement -