Here's one way to do it. It uses a temp table to create a sequential rowid (identity column) and uses that to self join to previous record:set nocount ondeclare @tb table (dt smalldatetime, val int)declare @temp table (rowid int identity, dt smalldatetime, val int)insert @tbselect '1/1/2005', 510 union allselect '2/1/2005', 620 union allselect '3/1/2005', 680 union allselect '3/12/2005', 640--generate sequetial rowids by inserting to table with identity and order byinsert @temp (dt,val)select dt,valfrom @tborder by dt asc--self join to previous recordselect a.dt dt1 ,b.dt dt2 ,PctChange = ((b.val - a.val) / convert(numeric(9,2), a.val)) * 100from @temp aJOIN @temp b ON a.rowid = b.rowid-1
Be One with the OptimizerTG