?
Solved

Get top level ParentId for a menu

Posted on 2006-06-26
2
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

800 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