I currently have the following SQL statement in a Stored Procedure;
SELECT [Id],
[Path],
[Title],
[Description]
FROM [Configuration].[Pages] p
WHERE
((p.Id = @Id) OR (@Id IS NULL)) AND
((p.Path = @Path) OR (@Path IS NULL))
This allows me to pass in either the path of the page, the id of the page or nothing (to return all).
I am looking to refactor this to return related child records (1 to M) rather than going back in the DB for each record returned. The current SQL for the child records is as follows;
SELECT h.Id, h.Description, h.Title, h.[Content]
FROM [Configuration].[HelpItems] h INNER JOIN
[Configuration].[PageHelpItems] ph ON h.Id = ph.HelpId
WHERE (ph.PageId = @PageId)
At present, I am looping through each of the parent records and calling this Stored Procedure for each, which I believe is inefficient and I would like to have one or more SQL statements with the SP that ensure the child records are returned for all parents.
So you want the record