Help with SQL Syntax Error

Build and share your cool customized reports built w/ one sql, Chart.js and Lua (https://github.com/moneymanagerex/general-reports)

Moderator: Renato

Post Reply
dimidimi
Super MMEX User
Posts: 37
Joined: Tue Mar 04, 2014 10:46 am
Are you a spam bot?: No

Help with SQL Syntax Error

Post by dimidimi »

I have tried the following using a couple of SQLLite utilities and both produced a result set. However when I insert in in the SQL portion of a custom report I get a syntax error :(

Code: Select all

 SELECT transcount.categname,
       transcount.subcategname,
       Sum(totalamounts.sumamounts) AS amounttotal,
       Count(*)                     AS counttotal,
       Sum(totalamounts.sumamounts) / Count(*)
FROM   (SELECT mo,
               categname,
               subcategname,
               nofentries
        FROM   [subcategory_v1] stab,
               [category_v1] ctab,
               (SELECT mo,
                       cid,
                       sid,
                       Count(*) AS nofentries
                FROM   (SELECT Strftime('%m', transdate) mo,
                               categid                   cid,
                               subcategid                sid,
                               transamount               amnt
                        FROM   [checkingaccount_v1]
                        WHERE  transcode = 'Withdrawal'
                               AND payeeid <> 15
                               AND categid <> -1
                        UNION
                        SELECT Strftime('%m', a.transdate) mo,
                               b.categid,
                               b.subcategid,
                               b.splittransamount
                        FROM   [checkingaccount_v1] a,
                               [splittransactions_v1] b
                        WHERE  a.transcode = 'Withdrawal'
                               AND a.payeeid <> 15
                               AND a.categid = -1
                               AND a.transid = b.transid)
                GROUP  BY mo,
                          cid,
                          sid) totalentries
        WHERE  stab.subcategid = totalentries.sid
               AND ctab.categid = totalentries.cid) transcount
       INNER JOIN (SELECT mo,
                          categname,
                          subcategname,
                          sumamounts
                   FROM   [subcategory_v1] stab,
                          [category_v1] ctab,
                          (SELECT mo,
                                  cid,
                                  sid,
                                  Sum(amnt) AS sumamounts
                           FROM   (SELECT Strftime('%m', transdate) mo,
                                          categid                   cid,
                                          subcategid                sid,
                                          transamount               amnt
                                   FROM   [checkingaccount_v1]
                                   WHERE  transcode = 'Withdrawal'
                                          AND payeeid <> 15
                                          AND categid <> -1
                                   UNION ALL
                                   SELECT Strftime('%m', a.transdate) mo,
                                          b.categid,
                                          b.subcategid,
                                          b.splittransamount
                                   FROM   [checkingaccount_v1] a,
                                          [splittransactions_v1] b
                                   WHERE  a.transcode = 'Withdrawal'
                                          AND a.payeeid <> 15
                                          AND a.categid = -1
                                          AND a.transid = b.transid)
                           GROUP  BY mo,
                                     cid,
                                     sid) totalentries
                   WHERE  stab.subcategid = totalentries.sid
                          AND ctab.categid = totalentries.cid) totalamounts
               ON transcount.mo = totalamounts.mo
                  AND transcount.categname = totalamounts.categname
                  AND transcount.subcategname = totalamounts.subcategname
GROUP  BY transcount.categname,
          transcount.subcategname  
Could anyone help here? Thanks!
Dimitrios

Nikolay
MMEX Developer
Posts: 1377
Joined: Sat Dec 06, 2008 2:27 pm
Are you a spam bot?: No
Location: Sankt-Petersburg, Russia

Re: Help with SQL Syntax Error

Post by Nikolay »

just add ; to the end of sql script

dimidimi
Super MMEX User
Posts: 37
Joined: Tue Mar 04, 2014 10:46 am
Are you a spam bot?: No

Re: Help with SQL Syntax Error

Post by dimidimi »

Very good! Thanks Nikolay! Heads back to researching about Lua and Templates. Any pointers on those would be really appreciated :) Thanks again!

Post Reply