Solved

Display Hierarchy In Column Format

Posted on 2006-06-15
7
591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

630 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