I do have the next query to be run in Access, It does well, but as you can see, there is a similitude in the first 3 SELECT
. I want to know if there is the possibility to optimize this, since I will be adding houndreds of
c
's.
SELECT id, IIF(c1>=0, c1, ) AS positive, IIF(c1<0, c1, ) AS negative FROM tblcostos
UNION ALL
SELECT id, IIF(c2>=0, c2, ) AS positive, IIF(c2<0, c2, ) AS negative FROM tblcostos
UNION ALL
SELECT id, IIF(c3>=0, c3, ) AS positive, IIF(c3<0, c3, ) AS negative FROM tblcostos
UNION ALL
SELECT 'sum positivo + negative' AS id, SUM(c1 + c2 + c3) AS positive, "" AS negative FROM tblcostos
ORDER BY id;
I require the final table to be shown like this, because I'll end up with a .txt with that format