Avatar of Rich Olu
Rich Olu
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

Fill missing cell entries from previous rows

I have a table with transactions.

The columns are:

trxid,date,payee,category,amount,split


trxid is sequential transaction ID although with gaps here and there.


Split is either blank or S. S is for when a row is the sum of following rows.


The problem is that the row which has S has date and the payee and the amount, while the following component transactions only have the amounts but no date or payee.


What I want to do is go through the table and fill in the empty date and payee where missing with the date and payee of the preceding row with the S entry in the split column.


Example

 

trxidDatePayeeCategoryAmountSplit
101/08/2000TescoShopping-10S
2

Shopping-8
3

Household-2
405/09/2000BPPetrol-100
506/09/2000BradyClothing-55
810/10/2000ArgosLaptop-400S
9

Laptop-329.99
10

Toys-70.01
1512/10/2000MaplinsElectronics-15.99
1615/10/2000HMRCStolen income-200
1715/10/2000EmployerSalary1000


So as you can see, trxid 2 and 3 are missing date and payee and they need to be the same date and payee as trxid 1.

Same things with trxid 9 and 10 inheriting date and payee of trxid 8.


Hope this is clear.


I have tried and failed so your help will be much appreciated.

Microsoft SQL Server* Oracle PL/SQLOracle DatabaseSQL

Avatar of undefined
Last Comment
Sean Stuber

8/22/2022 - Mon