I've got a piece of code (helpfully supplied by a kind user here) that uses LAG on a box running 2012.
I now have to use a box running 2008 and, of course, the query fails because SSMS doesn't understand what LAG is.
What is a 2008-friendly version of the following:
SELECT TransactionDate, Insurer, [Count] - LAG ([Count], 1, 0) OVER (PARTITION BY TransClass, PolicyReference ORDER BY TransactionDate), [Value] FROM [dbo].[MyTable] WHERE TransClass = 'YY' AND TransactionDate >= CONVERT (CHAR (8), DATEADD (DD, -7, GETDATE()), 112) AND TransactionDate < CONVERT (CHAR (8), GETDATE(), 112)
Many thanks for any nudges.