Solved

Display Hierarchy In Column Format

Posted on 2006-06-15
7
585 Views
Last Modified: 2008-03-04
Greetings,

I am using this hierarchy function listed below and query to display my hierarchy in this table called ticket_category_tmp.
 for sql server 2000:
create function hirearchy(@id as int) returns varchar(1000)
as
begin
declare @tree as varchar(1000)
set @tree = ''
if (parent_cat_code <> 0 and  parent_cat_code is not  null )

select @tree = dbo.hirearchy(parent_Cat_code) +'>' + description from ticket_category_tmp where id = @id

return @tree
end
go  

SELECT     ticket_category.id, dbo.hirearchy(ticket_category.id)
FROM         ticket_category
ORDER BY dbo.hirearchy(ticket_category.id)

The Results of this query display like this:

ID         Tree
===  =================
7       Admin>
15     Admin>HardWare
16     Admin> HardWare>MBOARD
17     Admin>NETWORK
18     Admin>NETWORK>OUTAGE
19     Admin>NETWORK>OUTAGE>VPN

I would like to have this display by columns instead of rows. Any solutions for this? The first colum would be the root or parent then the next column would be level 1, level 2, level 3, etc......

0
Comment
Question by:Omega002
  • 4
  • 2
7 Comments
 

Author Comment

by:Omega002
ID: 16912805
Also could you do this using cases?
0
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 16912814
SQL 2005 does use the PIVOT function to do that...OnSQL 2000 you will probably have to do some scripting for that...
0
 

Author Comment

by:Omega002
ID: 16912927
Can you show me how you would do it?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Omega002
ID: 16912938
Can you show me how you would use it in SQL 2005 using the pivot table?
0
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 16919287
Check the following link for more info...

http://msdn2.microsoft.com/en-us/library/ms177410.aspx

Hope this helps...
0
 

Author Comment

by:Omega002
ID: 16919690
The example from the link is count number values so how would I apply this to displaying hierarchy data?
SELECT     ticket_category.id, dbo.hirearchy(ticket_category.id)
FROM         ticket_category
ORDER BY dbo.hirearchy(ticket_category.id)

The Results of this query display like this:

ID         Tree
===  =================
7       Admin>
15     Admin>HardWare
16     Admin> HardWare>MBOARD
17     Admin>NETWORK
18     Admin>NETWORK>OUTAGE
19     Admin>NETWORK>OUTAGE>VPN

This is what I am looking for:
ID    Level 1      Level 2      Level 3
=     ======  =====    ======
7       Admin      HardWare MBOARD
 Can you show me how you would approach this?
0
 
LVL 28

Accepted Solution

by:
imran_fast earned 500 total points
ID: 16929451
it is very hard to acheive what you want because the levels are dynamic.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 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

19 Experts available now in Live!

Get 1:1 Help Now