0 votes

SQL procedure with unrelated tables

I need to do a stored procedure in SQL with three unrelated tables: ' ingreso , gasto , gastoVarios ', I have to show the total of montoFactIngreso of montoFactGasto and of montoFactVarios in one column each total, I used this select but it shows me the totals in a single column:

SELECT SUM(ingreso.montoFactIngreso)
FROM   ingreso
UNION
SELECT SUM(gasto.montoFactGasto)
FROM   gasto
UNION
SELECT SUM(gastoVarios.montoFactVarios)
FROM   gastoVarios

Tablas a usar en el procedimiento

3voto

Lamak Points 6294

For this you can simply use CROSS JOIN :

SELECT  G.Gasto,
        I.Ingreso,
        V.Varios
FROM (  SELECT SUM(montoFactGasto) Gasto
        FROM dbo.gasto) G
CROSS JOIN (SELECT SUM(montoFactIngreso) Ingreso
            FROM dbo.ingreso) I
CROSS JOIN (SELECT SUM(montoFactVarios) Varios
            FROM dbo.gastoVarios) V;

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X