Query between different databases in SQL Server

Asked

Viewed 1,179 times

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 queries in different databases, I do not know if this is a sql server imitation, but by including this restriction I have no result

For example, the funcionario Code 11014 does not exist in the working table of the database WebAdiantamento, soon should come in this consultation, but in the brings nothing.

That way it didn’t work either:

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

1 answer

0


I managed to solve, due to some records in the comic book WebAdiantamento are null and void, I couldn’t make the comparison, so I added a isnull in subquery and solved the problem.

isnull(WebAdiantamento.DBO.funcionario.CodigoFuncPonto,0) 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.