Prefixes in SQL Sentence

Asked

Viewed 837 times

3

In SQL Server it accepts only 4 prefixes in the sentences, e.g.: Select * from pmv.banco.dbo.tabela. In this case, I am using a client Linked server.

However, when I reference some field of the table, where would be 5 prefix (pmv.banco.dbo.tabela.campo), I can’t continue because SQL doesn’t accept it. Would you know a possible solution for this ? Could you give me tips ?

UPDATE LINK.base.dbo.Tabela  
   SET cliq.situacao = 'C'  
  FROM LINK.base.dbo.Tabela cliq
  JOIN #tmpTabela tmp ON tmp.idreferencia = cliq.idreferencia 
  JOIN BRMLiquidacoes anu ON anu.idbrmliquidacao = tmp.IdReferencia  
  JOIN BRMLiquidacoes mov ON mov.tipomov = 1 
   AND mov.unges = anu.unges 
   AND mov.brmano = anu.brmano 
   AND mov.brmnum = anu.brmnum 
   AND mov.anoint = anu.anoint 
   AND mov.numint = anu.numint 
   AND mov.empenho = anu.empenho 
   AND mov.anoemp  = anu.anoemp  
   AND mov.valor = ABS(anu.valor)  
  JOIN LINK.base.dbo.Tabela cp ON cp.IdReferencia = mov.idbrmliquidacao  
                                          AND cp.lancto_liquidacao_cp = 'N'  
                                          AND cp.situacao = 'A'  
                                          AND cp.IdReferencia = (  
SELECT MIN(smov.idbrmliquidacao) FROM BRMLiquidacoes smov   
  JOIN LINK.base.dbo.Tabela cp ON cp.IdReferencia = smov.idbrmliquidacao  
  AND cp.lancto_liquidacao_cp = 'N'  
  AND cp.situacao = 'A'  
  WHERE smov.tipomov = 1 AND smov.unges = anu.unges AND smov.brmano = anu.brmano AND smov.brmnum = anu.brmnum AND smov.anoint = anu.anoint AND smov.numint = anu.numint AND smov.empenho = anu.empenho AND smov.anoemp  = anu.anoemp  
  AND smov.valor = ABS(anu.valor)  
                                          )  
 WHERE tmp.excluir = 1 AND tmp.data_inclusao_brm IS NOT NULL
  • I updated my reply as per your update

1 answer

4


Just use a alias for each table, example:

SELECT tabela1.campo FROM pmv.banco.dbo.tabela AS tabela1

And in the update:

UPDATE tabela1
SET tabela1.campo2 = 'teste2'
FROM pmv.banco.dbo.tabela tabela1
WHERE tabela1.campo1 = 1;



UPDATE

Wrong name in your update, from:

UPDATE LINK.base.dbo.Tabela  
   SET cliq.situacao = 'C'  
  FROM LINK.base.dbo.Tabela cliq

To:

UPDATE cliq /* <-- aqui */
   SET cliq.situacao = 'C'  
  FROM LINK.base.dbo.Tabela cliq
  • Right. So for example, I’m doing an UPDATE where I use a temporaria with information. I ended up adapting and it was like this. Ex: UPDATE tables.field = 1 FROM pmv.banco.dbo.table tables Join #tmporario tmp ON tmp.field = tables.field .. However, SQL made an Ambiguous error.

  • @Sebastiãohenrique Your message was cut, but I will update the answer

  • Right I did it in UPDATE, but the way I explained in the comment above, it presents Ambiguos error. I thank you already.

  • @Sebastiãohenrique Show how you are doing and which column is giving ambiguous?

  • UPDATE PMV.BANCO.DBO.TABLE -- Error occurs in this first line, presenting PMV.BANCO.DBO.TABLE Ambiguos SET table.field = tmp.field FROM PMV.BANCO.DBO.TABLE JOIN #temporaria tmp ON tmp.id = table.id

  • Where did you put alias? You don’t seem to have used my solution @Sebastiãohenrique

  • @Sebastiãohenrique Edits your question with the full code you are trying to

  • Thanks man, it worked out!!

Show 3 more comments

Browser other questions tagged

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