Solved

Get top level ParentId for a menu

Posted on 2006-06-26
2
232 Views
Last Modified: 2006-11-18
My procedure takes a string parameter which represents a subpage item in a menu.
From that string I need to return the top level parent menu item, which will have
a ParentCategoryId of 0 (zero).

This is an example of the table:

CatId         Page name               ParentCategoryId
------         -------------               --------------------
2     Home Page     0
8     001-About Us     0
13     002-Our Neighborhoods     0
14     003-Featured Buildings     0
15     004-For Buyers     0
16     005-Our Listings     0
17     006-Testimonials     0
18     007-Our Team     0
19     008-RE News     0
20     009-For Investors     0
21     001-Area Information     13
22     002-Links     13
23     001-Services     15
24     002-Buyer Agency     15
25     003-Finance Center     15
26     001-Lenders     25
27     002-Mortgage Calculator / Tax Estimator     25
28     003-Dream Home Request     25
29     001-Due Diligence     20
30     002-Investment Types     20
31     003-Commercial Marketing Plan     20
9     001-Mission     8
10     002-Management     8
11     003-Careers     8
12     004-Contact Us     8

If the input parameter is "Dream Home Request", the ParentCategoryId = 25, or Finance Center.
The ParentCategoryId of Finance Center is 15, or For Buyers.
The ParentCategoryId of For Buyers is 0, so I need to return 15, because that is the top level
of the menu.

Can you help me write this stored procedure?

Thanks!
0
Comment
Question by:JeffDrummond
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 16985806
create procedure ReturnMainPage ( @Name varchar(40))
as
set nocount on
declare @pageid int
declare @parentid int

select @pageid = catid, @parentid = ParentCategoryid
from yourtable
where [Page name] = @name

set @parentid = coalesce(@parentid, 0)

while @parentid <> 0
begin
  select @pageid = catid, @parentid = ParentCategoryid
  from yourtable
  where catId = @parentid
end

select * from yourtable where catid = @pageid
0
 

Author Comment

by:JeffDrummond
ID: 16986012
Thanks angelIII.  Works perfectly!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question