CREATE PROCEDURE [dbo].[sp_getMenuElements_ByParentID] @pID as int AS BEGIN select id,page_name,(select count(*) FROM tTreeview WHERE parentid=sc.id) childnodecount, logical_name, aspxPagePath FROM tTreeview sc where parentID=@pID ORDER BY position END