Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2004, 01:53 PM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to seanmayhew
Default Need help with creating a Parent Category

I've added a new column called "ParentID" to the News_Categories table that holds unsurpsingly the "CategoryID" of the categories parent. This works fine when its one parent deep. So... Say I have 3 categories Cat1 - Cat2 - Cat3 if the ParentID for Cat3 is Cat1 it returns Cat1. This is okay. But if I make a Cat4 with a ParentID of Cat3 it returns Cat1 which would actually be the Grandparent! This is as deep as it goes If I add a Cat5 with ParentID of Cat4 it returns the Cat3 ID... the grandparent.

Here is my stored procedure

CREATE PROCEDURE sp_News_ParentCat
@CatID int
AS

DECLARE @HoldParentID int

SELECT @HoldParentID = ParentCatID
    FROM News_Categories
    WHERE CatID = @CatID

SELECT CatID, Name
    FROM News_Categories
    WHERE CatID = @HoldParentID
GO
 
Old November 10th, 2004, 10:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This looks inefficient. Why not try a subquery:

SELECT NC1.CatID, NC1.Name
FROM News_Categories NC1
WHERE NC1.CatID =
  (select NC2.ParentCatID
   FROM News_Categories NC2
   WHERE NC2.CatID = @CatID)

I suspect your real problem is with the data.

Eric
 
Old November 13th, 2004, 06:20 PM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to seanmayhew
Default

Actually this worked and it turned out my original was working but Im trying to give the user the friendly name of the category and not the category id. So for some reason it will display the correct parent category id but there is some sort of skip thats returning the grandparent name if I omit the function to get the friendly name i have the right ID displayed go figure.





Similar Threads
Thread Thread Starter Forum Replies Last Post
dropdownlist with heading for each category debjanib ASP.NET 2.0 Basics 5 May 16th, 2007 04:19 PM
Add category on Blog highspeedwire BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 January 26th, 2007 05:35 PM
Changing Category and/or News order seanmayhew BOOK: ASP.NET Website Programming Problem-Design-Solution 1 March 25th, 2005 01:46 PM
Category SubCategories and two MySQL tables cjp_qld PHP Databases 2 August 29th, 2004 04:14 AM
Listing Category then Items harpua Classic ASP Professional 3 December 12th, 2003 11:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.