0
I made a query that brings the values of credit and debit, but I need to bring only the values that are different from these two fields. At the moment I do not know why it is bringing all. Look at the image: OBS IS IN SQL SERVER
Sql code:
declare @data date='2018-05-21'
select * from (select sum (ContabLancValor) as debito,ContabLancNumCtrl,
CAST(ContabLancHistComp AS varchar(max)) as NomeCliente from
CONTAB_LANCAMENTO
where ContabLancData >=@data
and ContabLancData <=@data
and ContabLancCtaCred is not null
and EmpCod='01.02'
group by CAST(ContabLancHistComp AS varchar(max)), ContabLancNumCtrl)debito
inner join(
select sum (ContabLancValor) as credito,ContabLancNumCtrl from
CONTAB_LANCAMENTO
where ContabLancData >=@data
and ContabLancData <=@data
and ContabLancCtaDeb is not null
and EmpCod='01.02'
group by CAST(ContabLancHistComp AS varchar(max)), ContabLancNumCtrl) credito
on credito.ContabLancNumCtrl=debito.ContabLancNumCtrl
where debito.debito<>credito.credito
If you need to execute on
sql-server
, edit the question and remove the other sgbd’s to avoid doubts– Ricardo Pontual
select A.* from CONTAB_LANCAMENTO A inner join CONTAB_LANCAMENTO B on B.ID = A.ID and A.Valor != B.Valor
, with time I elaborate a complete answer– Rovann Linhalis