Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Join Statement

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.

like image 430
user1005479 Avatar asked Jun 09 '26 05:06

user1005479


1 Answers

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

like image 181
vulkanino Avatar answered Jun 10 '26 19:06

vulkanino