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.
Move you alias to after your delete, but you should also identify the table the
ArticleKeycomes from