Select the largest amount from a field in SQL Server 2000 Table

Hi all.

I have a SQL Server 2000 table (myTable) that has the following fields:


How do I select the largest Qty for each itemnumber from the previous month.

So let's say I have item: 123
Qty: 10--Date: 01/01/2011
Qty: 5--Date: 01/02/2011
Qty: 75--Date: 02/02/2011
Qty: 35--Date: 03/01/2011
Qty: 20--Date: 03/02/2011
Qty: 50--Date: 03/03/2011

The result should be 50 because I want the largest QTY amount from the PREVIOUS month.

Thank you in advance!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

select itemnumber, max(qty) qty
from table
where date = dateadd(mm, -1 ,convert(varchar,date,110))
group by itemnumber
SharathData EngineerCommented:
like this.
SELECT ItemNumber, 
         MAX(Qty) AS max_Qty 
    FROM myTable 
GROUP BY ItemNumber

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.