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)
 getting top 100

Author  Topic 

qwertyjjj
Posting Yak Master

131 Posts

Posted - 2008-06-27 : 11:27:26
I have a table which splits monthdata into separate datasets by the MonthData column (this is because each month is itself used in a report).
I need to get a top 100 client list out of this but the only unique reference is the docno, which is repeated in many months. I need to pick up the value from the latest month and then group it for a client.
Any ideas?

Sample data

docno client code amount month
9110422 FGH112 100 06/2008
912467 ASD112 99 06/2008
9110422 FGH112 100 05/2008



So, a report on the above ignores the older entry in 05/2008 and anything in 04/2008, 03/2008, etc.
But the latest entry for one of the other invoices for client FGH112 might have been a few months ago as well.
Essentially a turnover report.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-27 : 12:41:46
not quite clear. do you mean you need top 100 distinct client list in decreasing order of month?
Go to Top of Page

qwertyjjj
Posting Yak Master

131 Posts

Posted - 2008-06-30 : 07:30:05
Top 100 by invoice amount
So with

docno client code amount month
9110422 FGH112 100 06/2008
912467 ASD112 99 06/2008
9110422 FGH112 100 05/2008
9110199 FGH112 50 03/2008


I would expect a result saying
FGH112 150
ASD112 99

docno's are not unique, I could use a temporary table maybe but prefer to use it on the fly.
Also, it has to look historically and pick up a docno plus amount evcen if it isn't in the current month.
Go to Top of Page
   

- Advertisement -