Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hierarchical Query Help

Status
Not open for further replies.

TamedTech

IS-IT--Management
Joined
May 3, 2005
Messages
998
Location
GB
Hello Guys and Girls,

I'm completely new to Hierarchical Queries and so I'm feeling a little lost, I've read through some litterature on the web but it all seems rather complex to me at the moment, so I'm after a little help and hopefully I'll learn somthing from you.

Basicly this query is to build a menu for a website, It will be querying a table, pulling the names for the pages, grouped into thier hierachy. All pages are kept in a single table called 'Article' and have a column called 'Parent_ID' which links to the 'Article_ID' column to identify the hierachy. The idea being I think that if a page is at the top level of the menu it has a Parent_ID of 0? or should that be NULL?

I'm running SQL Server 2005 and I've copied the create script for the table below, just to help your life a little easier.

Code:
CREATE TABLE [dbo].[Article](
	[Article_ID] [int] IDENTITY(1,1) NOT NULL,
	[Parent_ID] [int] NOT NULL,
	[Title] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[ShortDescription] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[Heading] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[SubHeading] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
	[ArticleContent] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[Alive] [bit] NOT NULL,
	[IncludeRSS] [bit] NOT NULL,
	[Featured] [bit] NOT NULL,
	[User_ID] [int] NOT NULL,
	[DateCreated] [datetime] NOT NULL,
	[DateModified] [datetime] NOT NULL,
 CONSTRAINT [PK_Article] PRIMARY KEY CLUSTERED 
(
	[Article_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

The final query results will be used to draw a nested XHTML list which creates the sites menu.

Thanks for any help you can offer guys, I've been going bald with dispare trying to figure this one out :-D

Thanks,

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top