View Single Post
  #4 (permalink)  
Old March 25th, 2008, 03:12 PM
dparsons dparsons is offline
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Your original post used the example of top 10 hence my examples used top 10.

Now I don't seem to understand your problem. Quickly I typed up this code:

DECLARE @tbl table ([Month] datetime, sname varchar(50), Savings int)
INSERT INTO @tbl([month], sname, savings)
Values('01/01/2008', 'John', 500)

INSERT INTO @tbl([month], sname, savings)
Values('01/01/2008', 'Mike', 250)

INSERT INTO @tbl([month], sname, savings)
Values('01/01/2008', 'Jane', 50)

INSERT INTO @tbl([month], sname, savings)
Values('02/01/2008','John', 500)

INSERT INTO @tbl([month], sname, savings)
Values('02/01/2008', 'Shane',400)

INSERT INTO @tbl([month], sname, savings)
Values('02/01/2008', 'Mike',350)

INSERT INTO @tbl([month], sname, savings)
Values('03/01/2008','Jane', 700)

INSERT INTO @tbl([month], sname, savings)
Values('03/01/2008','John', 500)

INSERT INTO @tbl([month], sname, savings)
Values('03/01/2008','Mark', 200)

SELECT Top 3 [month], sname, savings from @tbl order by DatePart(Month, [Month]) desc, savings desc

My resultset was

MONTH Sname Savings
2008-03-01 Jane 700
2008-03-01 John 500
2008-03-01 Mark 200

Is this not what you want??

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote