Solved

Get top level ParentId for a menu

Posted on 2006-06-26
2
236 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 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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 ?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

707 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