Solved

Get top level ParentId for a menu

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SLQ View not updating 10 47
PL/SQL query 14 46
Choosing SSD drives for SQL Server 32 78
Complex SQL 10 33
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now