Given this query:
SELECT
PontoSecullum4.DBO.funcionarios.N_FOLHA,
PontoSecullum4.DBO.funcionarios.NOME,
PontoSecullum4.DBO.funcionarios.EMPRESA_ID,
1 [ORIGEM]
FROM
PontoSecullum4.DBO.funcionarios
WHERE 1=1
AND NOT EXISTS(
SELECT CodigoFuncPonto
FROM WebAdiantamento.DBO.funcionario
WHERE FUNCIONARIO.CodigoEmpresa = 3
)
AND PontoSecullum4.DBO.funcionarios.n_folha = 11014
AND PontoSecullum4.DBO.funcionarios.empresa_id = 3
AND PontoSecullum4.DBO.funcionarios.demissao IS NULL
As you can see it does query on different banks, I do not know if this is a limitation of the sql server, but when I include this restriction I have no results.
For example, funcionario
of code 11014 does not exist in the official database table WebAdiantamento
, so it should come in this query, but nothing.
This also did not work:
SELECT
PontoSecullum4.DBO.funcionarios.N_FOLHA,
PontoSecullum4.DBO.funcionarios.NOME,
PontoSecullum4.DBO.funcionarios.EMPRESA_ID,
1 [ORIGEM]
FROM
PontoSecullum4.DBO.funcionarios
WHERE 1=1
AND PontoSecullum4.DBO.funcionarios.N_FOLHA NOT IN (
SELECT CodigoFuncPonto
FROM WebAdiantamento.DBO.funcionario
WHERE FUNCIONARIO.CodigoEmpresa = 3
)
AND PontoSecullum4.DBO.funcionarios.n_folha = 11014
AND PontoSecullum4.DBO.funcionarios.empresa_id = 3
AND PontoSecullum4.DBO.funcionarios.demissao IS NULL