Monday, 19 August 2013

Find the Last Price that is different from the Current Price

Find the Last Price that is different from the Current Price

I have sales transactions in a Microsoft SQL table like below:
ItemNumber, TrxDate, UnitPrice
ABC, 1/1/2013, 10.00
ABC, 2/1/2013, 10.00
ABC, 3/1/2013, 13.00
ABC, 4/1/2013, 14.00
ABC, 5/1/2013, 14.00
XYZ, 1/1/2013, 18.00
XYZ, 2/1/2013, 18.00
XYZ, 3/1/2013, 20.00
XYZ, 4/1/2013, 20.00
XYZ, 5/1/2013, 20.00
I need a stored procedure to produce output that would look like this
ItemNumber, LastPrice, PriorPrice
ABC, 14.00, 13.00
XYZ, 20.00, 18.00
I've struggled with this for a while.
Your help is appreciated.
Thanks.

No comments:

Post a Comment