Hi All,I have the following query built as a View in SQL.SELECT T2.CardCode, T2.CardName, T0.DocNum, T0.DocType, T1.ItemCode, T1.Dscription, T1.Quantity, T0.DocDate, T1.Price, T1.Currency, 0 AS [Previous DocNum], 0 AS [Previous Price]FROM dbo.ORDR AS T0 INNER JOIN dbo.RDR1 AS T1 ON T0.DocEntry = T1.DocEntry INNER JOIN dbo.OCRD AS T2 ON T0.CardCode = T2.CardCodeORDER BY T0.DocNum DESC
I need to populate the [Previous DocNum] and [Previous Price] columns where the ItemCode and CardCode are the same and the DocNum is the next lowest value than the current row DocNum value.I could do this with some VB code in my frontend but would like to try to do it at the database level as there are 73,000 rows!Not got much experience with this level of SQL...Can anyone help?Thanks In Advance,John