Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 10th, 2004, 12: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
  #2 (permalink)  
Old November 10th, 2004, 09: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
  #3 (permalink)  
Old November 13th, 2004, 05: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.

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 04:35 PM
Changing Category and/or News order seanmayhew BOOK: ASP.NET Website Programming Problem-Design-Solution 1 March 25th, 2005 12: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 10:47 AM



All times are GMT -4. The time now is 12:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.