Prefixes in SQL Statement

3

In SQL Server it only accepts 4 prefixes in sentences, eg Select * from pmv.banco.dbo.tabela . In this case, I'm using a client linked server.

However, when I refer to some table field, where I would get a prefix ( pmv.banco.dbo.tabela.campo ), I can not continue because SQL does not accept it. Would you know a possible solution to 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
    
asked by anonymous 16.06.2015 / 18:16

1 answer

4

Just use alias for each table, for example:

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

And no update :

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



UPDATE

The name in your update is incorrect, 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
    
16.06.2015 / 18:17