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
SELECT SUM(gasto.montoFactGasto)
FROM   gasto
SELECT SUM(gastoVarios.montoFactVarios)
FROM   gastoVarios

Tablas a usar en el procedimiento


Lamak Points 6294

For this you can simply use CROSS JOIN :

SELECT  G.Gasto,
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 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: