How to interpret * in this query

Asked

Viewed 83 times

0

I got a query which, apparently, is simple if it weren’t for the fact that I have these two * Alas, I’m not sure if it’s inner join, left join or someone from the same family.

I need to turn this query for linq to sql, and the result is not working. Can anyone help me interpret this? I did left join and it didn’t add up.

select AFENTIDADE.NOMEENTIDADE, NOMEAO, NOMEUTILIZADOR,
MN.DATACRIA, MN.DATAFECHO, MN.NUMFACT,
MN.NUMFOLHA, AESERVICO.TempoEI, HORASA, R.PRECOD
From AEMANUTE MN WITH (NOLOCK), AFENTIDADE WITH (NOLOCK), AREGDOC R WITH (NOLOCK),
UTILIZADORES WITH (NOLOCK), AESERVICO WITH (NOLOCK),  AIAREAORGANICA WITH (NOLOCK)
Where  (MN.CODENTIDADE=AFENTIDADE.CODENTIDADE
And MN.CODAO=AIAREAORGANICA.CODAO
AND MN.CODAO *=R.CODAO
And MN.numfolha=aeservico.numfolha
And MN.numfact *= R.numfact
And aeservico.codutilizador=utilizadores.codutilizador
AND UTILIZADORES.ANULADO IS NULL 
AND
R.coddoc='FM') And 
R.STATUS<>'E' And
MN.IdSituacao=5
--or MN.IdSituacao=5) 
And
LEFT(MN.datafecho, 10) >='2017-04-01' And LEFT(MN.datafecho, 10)  <='2017-04-30' 
ORDER BY  NOMEAO, NOMEUTILIZADOR, AFENTIDADE.NOMEENTIDADE
  • Take a look here, I think this is your case: http://stackoverflow.com/questions/983862/sql-server-operator

1 answer

2

At first the construction *= is the same as LEFT JOIN.

Constructions of the type

-- código #1
SELECT T1.codigo, T2.nome
  from tab1 as T1, tab2 as T2
  where T1.codigo *= T2.codigo;

are usually converted to

-- código #2
SELECT T1.codigo, T2.nome
  from tab1 as T1
       left outer join tab2 as T2 on T1.codigo = T2.codigo;

However, the returned result may be slightly different depending on the other conditions involved and the DBMS.


Follow conversion suggestion for your code; evaluate it carefully as it has not been tested.

-- código #3
SELECT ...
  from  AEMANUTE as MN
        inner join AFENTIDADE on AFENTIDADE.CODENTIDADE = MN.CODENTIDADE
        left outer join AREGDOC as R on R.CODAO = M.CODAO and R.numfact = MN.numfact
        inner join AESERVICO on aeservico.numfolha = MN.numfolha
        inner join UTILIZADORES on utilizadores.codutilizador = aeservico.codutilizador
        inner join AIAREAORGANICA on AIAREAORGANICA.CODAO = MN.CODAO
  where UTILIZADORES.ANULADO IS NULL 
        and (R.coddoc is null or R.coddoc = 'FM')
        and (R.STATUS is null or R.STATUS <> 'E')
        and MN.IdSituacao = 5
        and LEFT(MN.datafecho, 10) >='2017-04-01' And LEFT(MN.datafecho, 10)  <='2017-04-30' 
  order by NOMEAO, NOMEUTILIZADOR, AFENTIDADE.NOMEENTIDADE;

Reading suggestion

  • Thank you very much, I understood it better and so ,I managed to pass it to Inq to sql

  • @Don’t forget to accept the answer if it has helped you, so other users with the same question can benefit from your question in the future

Browser other questions tagged

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