Omega002
asked on
Display Hierarchy In Column Format
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_c ode) +'>' + description from ticket_category_tmp where id = @id
return @tree
end
go
SELECT ticket_category.id, dbo.hirearchy(ticket_categ ory.id)
FROM ticket_category
ORDER BY dbo.hirearchy(ticket_categ ory.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......
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_c
return @tree
end
go
SELECT ticket_category.id, dbo.hirearchy(ticket_categ
FROM ticket_category
ORDER BY dbo.hirearchy(ticket_categ
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......
SQL 2005 does use the PIVOT function to do that...OnSQL 2000 you will probably have to do some scripting for that...
ASKER
Can you show me how you would do it?
ASKER
Can you show me how you would use it in SQL 2005 using the pivot table?
Check the following link for more info...
http://msdn2.microsoft.com/en-us/library/ms177410.aspx
Hope this helps...
http://msdn2.microsoft.com/en-us/library/ms177410.aspx
Hope this helps...
ASKER
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_categ ory.id)
FROM ticket_category
ORDER BY dbo.hirearchy(ticket_categ ory.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?
SELECT ticket_category.id, dbo.hirearchy(ticket_categ
FROM ticket_category
ORDER BY dbo.hirearchy(ticket_categ
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER