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

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

mjimenezh
Yak Posting Veteran

Mexico
61 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
FROM         dbo.View_VK_PURCHASE_PRICE

khtan
In (Som, Ni, Yak)

Singapore
17584 Posts

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


KH
Time is always against us

Go to Top of Page

maunishq
Yak Posting Veteran

Canada
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.
!_(M)_!
Go to Top of Page

mjimenezh
Yak Posting Veteran

Mexico
61 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  
 New 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.03 seconds. Powered By: Snitz Forums 2000