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
 General SQL Server Forums
 New to SQL Server Programming
 Recent Date

Author  Topic 

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-03-04 : 20:27:16
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
FROM dbo.View_VK_PURCHASE_PRICE

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-04 : 20:31:58
refer to http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=192905


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

Go to Top of Page

maunishq
Yak Posting Veteran

71 Posts

Posted - 2014-03-05 : 10:35:17
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.
!_(M)_!
Go to Top of Page

mjimenezh
Yak Posting Veteran

81 Posts

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

Go to Top of Page
   

- Advertisement -