Eliminar declaración de unión

I am trying to use Delete statement in my Stored Procedure but it is giving me an error saying,

Invalid object name 'BRWSQLDC'.

and below is my Delete Statement:

set @Query = 'DELETE FROM ' + @DestLinkServer + ' FROM .HL2_61.dbo.ArtPDF AP JOIN .HL2_61.dbo.Article A on A.ArticleID = AP.ArticleID ' + ' WHERE ArticleKey = ' + CONVERT(VARCHAR, @Id)

When I execute it as below

DELETE FROM BRWSQLDC FROM .HL2_61.dbo.ArticlePDF AP JOIN .HL2_61.dbo.Article A on A.ArticleID = AP.ArticleID  WHERE ArticleKey = -1591276581

Error is: Invalid object name 'BRWSQLDC'.

And if I try to execute the code as below:

'DELETE FROM ' + @DestLinkServer + ' .HL2_61.dbo.ArticlePDF AP JOIN .HL2_61.dbo.Article A on A.ArticleID = AP.ArticleID ' + ' WHERE ArticleKey = ' + CONVERT(VARCHAR, @Id)

when passing the values,

DELETE FROM BRWSQLDC .HL2_61.dbo.ArticlePDF AP JOIN .HL2_61.dbo.Article A on A.ArticleID = AP.ArticleID  WHERE ArticleKey = -1591276581

error I am getting is:

Incorrect syntax near 'AP'.

Please help me how to join 2 tables in a delete and then delete that in the server if it exists.

preguntado el 01 de febrero de 12 a las 14:02

3 Respuestas

You don't need a join but a proper WHERE clause.

Respondido 01 Feb 12, 18:02

Move you alias to after your delete, but you should also identify the table the ArticleKey viene de

DELETE AP
FROM BRWSQLDC.HL2_61.dbo.ArticlePDF AP 
JOIN BRWSQLDC.HL2_61.dbo.Article A   -- preface this with your server name for clarity
    ON A.ArticleID = AP.ArticleID  
WHERE A.ArticleKey = -1591276581 

Respondido 01 Feb 12, 18:02

When you use join you have to tell from which table you want to delete rows:

DELETE dbo.Customer
FROM dbo.Customer cust INNER JOIN dbo.Person pers ON pers.ID_CUST = cust.ID_CUST

Respondido 01 Feb 12, 18:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.