Have the following error in sql server:
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement should be terminated with a semicolon
What can it be?
Follow the code:
declare @data date='2018-05-21'
With SomaDebCred AS (
SELECT ContabLancNumCtrl,
sum(case when ContabLancCtaCred is not null then ContabLancValor else 0
end) as soma_debito,
sum(case when ContabLancCtaDeb is not null then ContabLancValor else 0
end) as soma_credito
from CONTAB_LANCAMENTO
where ContabLancData = @data
and EmpCod='01.02'
group by ContabLancNumCtrl
),
NomeClientes AS (
SELECT A.ContabLancNumCtrl, A.soma_debito, A.soma_credito,
L.ContabLancValor, L.ContabLancHistComp,
L.ContabLancCtaCred, L.ContabLancCtaDeb
from SomaDebCred as A
inner join CONTAB_LANCAMENTO as L on L.ContabLancNumCtrl =
A.ContabLancNumCtrl
where A.soma_debito <> A.soma_credito
)
SELECT * FROM SomaDebCred
UNION ALL
SELECT * FROM NomeClientes