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.
You don't need a join but a proper WHERE clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With