Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Recent Date
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

81 Posts

Posted - 03/04/2014 :  20:27:16  Show Profile  Reply with Quote
Hi everyone, I have a script that gives me all the information about the Items Purchase, my problem is because every Item has several lots and I need just the Lot with the Most recent date (LotDate) but I don't know how can I do it, this is my code, thanks in advance :
SELECT     CreditorNumber, Supplier, ItemCode, Description, PurchasePackage, PurchasePrice, PurchaseCurrency, XRate, IVA, DeliveryDays, LotNumber, LotDate

In (Som, Ni, Yak)

17689 Posts

Posted - 03/04/2014 :  20:31:58  Show Profile  Reply with Quote
refer to

Time is always against us

Go to Top of Page

Yak Posting Veteran

71 Posts

Posted - 03/05/2014 :  10:35:17  Show Profile  Reply with Quote
you can use MAX(LotDate) OVER (PARTITION BY LotNumber ORDER BY LotNumber)

or use MAX(LotDate) and then Group By all other columns

Not an Expert, Just a learner.
Go to Top of Page

Yak Posting Veteran

81 Posts

Posted - 03/05/2014 :  10:48:41  Show Profile  Reply with Quote
I made the changes that You Recommend and it solved my problem, thanks Maunishq.

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000