Based on GMB's answer on my previous question I've simplified the query:
SELECT tn.Date,
case when tn.DrControl = 7
then b1.Name || ' -> ' || c1.Name || ' ' || ifnull(l1.Name, '') || ' ' || ifnull(s1.Name, '') || ' ' || ifnull(p1.Name, '') || ' ' || ifnull(m1.Name , '')
else b2.Name || ' -> ' || c2.Name || ' ' || ifnull(l2.Name, '') || ' ' || ifnull(s2.Name, '' ) || ' ' || ifnull(p2.Name, '') || ' ' || ifnull(m2.Name, '')
end Particulars,
case when tn.DrControl = 7 then tn.Amount end DrAmount,
case when tn.CrControl = 7 then tn.Amount end CrAmount,
tn.Narration
FROM Transactions tn
LEFT JOIN Books b1 ON b1.Id = tn.DrBook
LEFT JOIN Books b2 ON b2.Id = tn.CrBook
LEFT JOIN ControlLedgers c1 ON c1.Id = tn.DrControl
LEFT JOIN ControlLedgers c2 ON c2.Id = tn.CrControl
LEFT JOIN Ledgers l1 ON l1.Id = tn.DrLedger
LEFT JOIN Ledgers l2 ON l2.Id = tn.CrLedger
LEFT JOIN SubLedgers s1 ON s1.Id = tn.DrSubLedger
LEFT JOIN SubLedgers s2 ON s2.Id = tn.CrSubLedger
LEFT JOIN Parties p1 ON p1.Id = tn.DrParty
LEFT JOIN Parties p2 ON p2.Id = tn.CrParty
LEFT JOIN Members m1 ON m1.Id = tn.DrMember
LEFT JOIN Members m2 ON m2.Id = tn.CrMember
WHERE 7 IN (tn.DrControl, tn.CrControl)
to reduce the overhead of creating a Particulars
column in Application code. It produces result like this:
Date Particulars DrAmount CrAmount Narration
----------------------------------------------------------------------------------------
2020-06-13 Current Assets -> Cash In Hand Emon 100000 NULL Some Text
What I want now is to put a ->
in between Cash In Hand
and Emon
, for example, if that column is not null, otherwise empty string.