Query between different banks in SQL Server

0

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
    
asked by anonymous 09.06.2016 / 22:34

1 answer

0

I was able to resolve, because some records in the BD WebAdiantamento are null, I could not make the comparison, so I added isnull to the subquery and solved the problem.

isnull(WebAdiantamento.DBO.funcionario.CodigoFuncPonto,0) 
    
09.06.2016 / 22:51