D
Diogo
I have a query with a union that works fine, which sorts my records has I
want, nevertheless I wanted to add four totals at the end of the query, in
order to do that I joined them with union all otherwise it would screew up
the sorting if I only used the union clause. But nevertheless it screws up
the same, what I'm I doing wrong:
SELECT Servicos_Diarios_consolidado.Data, Servicos_Diarios_consolidado.[Tipo
de Documento], Servicos_Diarios_consolidado.Nº,
Servicos_Diarios_consolidado.[Tipo de Serviço],
Servicos_Diarios_consolidado.Advogado, Servicos_Diarios_consolidado.Assunto,
Servicos_Diarios_consolidado.Valor, Servicos_Diarios_consolidadbservações,
Servicos_Diarios_consolidado.[Recebido por], Servicos_Diarios_consolidado.[ID
Loja]
FROM Servicos_Diarios_consolidado
WHERE (Servicos_Diarios_consolidado.[Tipo de Documento]='Venda a Dinheiro'
And ((Servicos_Diarios_consolidado.Data) Between
Forms!frmREPORTS_CONSOLIDADO!Data_Inicio And
Forms!frmREPORTS_CONSOLIDADO!Data_Fim))
UNION all SELECT Servicos_Diarios_consolidado.Data,
Servicos_Diarios_consolidado.[Tipo de Documento],
Servicos_Diarios_consolidado.Nº, Servicos_Diarios_consolidado.[Tipo de
Serviço], Servicos_Diarios_consolidado.Advogado,
Servicos_Diarios_consolidado.Assunto, Servicos_Diarios_consolidado.Valor,
Servicos_Diarios_consolidadbservações,
Servicos_Diarios_consolidado.[Recebido por], Servicos_Diarios_consolidado.[ID
Loja]
FROM Servicos_Diarios_consolidado
WHERE (Servicos_Diarios_consolidado.[Tipo de Documento]='Factura' And
((Servicos_Diarios_consolidado.Data) Between
Forms!frmREPORTS_CONSOLIDADO!Data_Inicio And
Forms!frmREPORTS_CONSOLIDADO!Data_Fim))
UNION ALL SELECT "" as X1, "" as X2, "" as X3, "TOTAL RECEITAS" as X4, "" as
X5, "" as X6, Sum(Servicos_Diarios_consolidado!Valor) AS SOMATÓRIO1, "" as
X8, "" as X9, "" as X10
FROM Servicos_Diarios_consolidado
WHERE (((Servicos_Diarios_consolidado.Data) Between
[Forms]![frmREPORTS_CONSOLIDADO]![Data_Inicio] And
[Forms]![frmREPORTS_CONSOLIDADO]![Data_Fim]))
UNION ALL SELECT "" as X1, "" as X2, "" as X3, "TOTAL DESPESAS CLIENTES" as
X4, "" as X5, "" as X6, Sum(Despesas.Valor) AS SOMATÓRIO2, "" as X8, "" as
X9, "" as X10
FROM Despesas
WHERE (((Despesas.Data) Between
[Forms]![frmREPORTS_CONSOLIDADO]![Data_Inicio] And
[Forms]![frmREPORTS_CONSOLIDADO]![Data_Fim]))
UNION ALL SELECT "" as X1, "" as X2, "" as X3, "LUCRO" as X4, "" as X5, ""
as X6, z1!SOMATÓRIO1-z2!SOMATÓRIO2 AS LUCRO, "" as X8, "" as X9, "" as X10
FROM z1, z2
UNION ALL SELECT "" as X1, "" as X2, "" as X3, "NUMERARIO A DEPOSITAR" as
X4, "" as X5, "" as X6, z3!SOMATÓRIO1-z2!SOMATÓRIO2 AS [Numerario a
Depositar], "" as X8, "" as X9, "" as X10
FROM z2, z3;
Help please...
want, nevertheless I wanted to add four totals at the end of the query, in
order to do that I joined them with union all otherwise it would screew up
the sorting if I only used the union clause. But nevertheless it screws up
the same, what I'm I doing wrong:
SELECT Servicos_Diarios_consolidado.Data, Servicos_Diarios_consolidado.[Tipo
de Documento], Servicos_Diarios_consolidado.Nº,
Servicos_Diarios_consolidado.[Tipo de Serviço],
Servicos_Diarios_consolidado.Advogado, Servicos_Diarios_consolidado.Assunto,
Servicos_Diarios_consolidado.Valor, Servicos_Diarios_consolidadbservações,
Servicos_Diarios_consolidado.[Recebido por], Servicos_Diarios_consolidado.[ID
Loja]
FROM Servicos_Diarios_consolidado
WHERE (Servicos_Diarios_consolidado.[Tipo de Documento]='Venda a Dinheiro'
And ((Servicos_Diarios_consolidado.Data) Between
Forms!frmREPORTS_CONSOLIDADO!Data_Inicio And
Forms!frmREPORTS_CONSOLIDADO!Data_Fim))
UNION all SELECT Servicos_Diarios_consolidado.Data,
Servicos_Diarios_consolidado.[Tipo de Documento],
Servicos_Diarios_consolidado.Nº, Servicos_Diarios_consolidado.[Tipo de
Serviço], Servicos_Diarios_consolidado.Advogado,
Servicos_Diarios_consolidado.Assunto, Servicos_Diarios_consolidado.Valor,
Servicos_Diarios_consolidadbservações,
Servicos_Diarios_consolidado.[Recebido por], Servicos_Diarios_consolidado.[ID
Loja]
FROM Servicos_Diarios_consolidado
WHERE (Servicos_Diarios_consolidado.[Tipo de Documento]='Factura' And
((Servicos_Diarios_consolidado.Data) Between
Forms!frmREPORTS_CONSOLIDADO!Data_Inicio And
Forms!frmREPORTS_CONSOLIDADO!Data_Fim))
UNION ALL SELECT "" as X1, "" as X2, "" as X3, "TOTAL RECEITAS" as X4, "" as
X5, "" as X6, Sum(Servicos_Diarios_consolidado!Valor) AS SOMATÓRIO1, "" as
X8, "" as X9, "" as X10
FROM Servicos_Diarios_consolidado
WHERE (((Servicos_Diarios_consolidado.Data) Between
[Forms]![frmREPORTS_CONSOLIDADO]![Data_Inicio] And
[Forms]![frmREPORTS_CONSOLIDADO]![Data_Fim]))
UNION ALL SELECT "" as X1, "" as X2, "" as X3, "TOTAL DESPESAS CLIENTES" as
X4, "" as X5, "" as X6, Sum(Despesas.Valor) AS SOMATÓRIO2, "" as X8, "" as
X9, "" as X10
FROM Despesas
WHERE (((Despesas.Data) Between
[Forms]![frmREPORTS_CONSOLIDADO]![Data_Inicio] And
[Forms]![frmREPORTS_CONSOLIDADO]![Data_Fim]))
UNION ALL SELECT "" as X1, "" as X2, "" as X3, "LUCRO" as X4, "" as X5, ""
as X6, z1!SOMATÓRIO1-z2!SOMATÓRIO2 AS LUCRO, "" as X8, "" as X9, "" as X10
FROM z1, z2
UNION ALL SELECT "" as X1, "" as X2, "" as X3, "NUMERARIO A DEPOSITAR" as
X4, "" as X5, "" as X6, z3!SOMATÓRIO1-z2!SOMATÓRIO2 AS [Numerario a
Depositar], "" as X8, "" as X9, "" as X10
FROM z2, z3;
Help please...