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)
以减少在应用程序代码中创建Particulars
列的开销。它产生这样的结果:
Date Particulars DrAmount CrAmount Narration
----------------------------------------------------------------------------------------
2020-06-13 Current Assets -> Cash In Hand Emon 100000 NULL Some Text
我现在想要的是->
在Cash In Hand
and之间放置一个Emon
,例如,如果该列不为空,否则为空字符串。