Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with manipulating data

Author  Topic 

Kiemo
Starting Member

1 Post

Posted - 2009-08-25 : 08:32:04
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.CardCode
ORDER 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
   

- Advertisement -