I have the following Audit table for Stock Items
ItemHistory
ItemNo,LogNo,Price,Date, and some other columns
Each time an item in my table gets updated it writes to this table for every ItemNo change it increments the LogNo for that Item.
So the data consists of (simplified)
001,1,100,2015/01/01
001,2,100,2015/01/04
001,3,200,2015/01/07
002,1,110,2015/01/01
002,1,120,2015/01/10
002,2,120,2015/01/04
002,3,120,2015/01/06
002,4,120,2015/01/30
etc
I need a date range for the price changes for item.
So I want output as
ItemCode,Pricem,DateStart,DateEnd
001,100,2015/01/01,2015/01/07
001,200,2015/01/07,todaysdate(2015/05/15)
002,110,2015/01/01,2015/01/10
002,120,2015/01/10,todaysdate(2015/05/15)
The audit table is very large so I want the best performance type query.
Can someone point me in the right direction?