0

I have used Aasim Abdullah's stored procedure to dynamically generate code for deletion of child tables, based on parent with certain filter condition. But I am getting a output which is not proper (Query 1). I would like to have output mentioned in Query 2.

--[Patient] is the Parent table, [Case] is child table and [ChartInstanceCase] is grand child --When I am deleting a grand child table, it should be linked to child table first followed by Parent

Query 1

DELETE Top(100000) FROM [dbo].[ChartInstanceCase]
FROM [dbo].[Patient] 
INNER JOIN [dbo].[Case]              ON [Patient].[PatientID]        = [Case].[PatientID]
INNER JOIN [dbo].[ChartInstanceCase] ON [ChartInstanceCase].[CaseId] = [Case].[CaseID]
WHERE [Patient].PracticeID = '55';

Query 2

DELETE Top(100000) [dbo].[ChartInstanceCase]
FROM  [dbo].[ChartInstanceCase] 
INNER JOIN [dbo].[Case]    ON [ChartInstanceCase].[CaseId] = [Case].[CaseID] 
INNER JOIN [dbo].[Patient] ON [Patient].[PatientID]        = [Case].[PatientID]
WHERE [Patient].PracticeID = '55';

Please let me know how I should modify the SP dbo.uspCascadeDelete to get the output as Query 2?

Community
  • 1
  • 1
  • The *textual* ordering of tables within a query is largely irrelevant. So far as I can see, the two queries are "the same" from an information perspective and should have identical effects. – Damien_The_Unbeliever Apr 21 '15 at 07:18
  • And what is wrong with the first? Post the stored procedure you need help with - don't expect us to get look it up. – paparazzo Apr 21 '15 at 12:16

0 Answers0