Einzelnen Beitrag anzeigen

NormanNG

Registriert seit: 1. Feb 2006
294 Beiträge
 
Delphi 2007 Professional
 
#6

Re: Kategorisierte Struktur sortieren (stored procedure/Curs

  Alt 22. Apr 2008, 14:29
Hi,

ich hab auch noch´n Versuch:

SQL-Code:
CREATE Procedure ListSubTree (@cat_id int)
as

declare @ChildID int
declare @Table Table (
  pfad varchar(100),
  ID INT,
  PID INT,
  NAME VARCHAR(1000)
)

-- 1.Zeile in die Tabelle

insert into @Table
  select cat_id, cat_id, cat_pid, cat_name from cate where cat_id = @cat_id


Declare c Cursor local for select ID from @Table
open c
fetch next from c into @ChildID
 while @@Fetch_status = 0 begin

-- Mit jedem Schleifendurchlauf werden in einem Abwasch ALLE Kindknoten eingefügt

  insert into @Table
    select t.pfad + '-' + convert(varchar, cat_id), cat_id, cat_pid, cat_name
      from cate c
      join @table t on t.id = c.cat_pid
      where cat_pid = @ChildID
  fetch next from c into @ChildID
 end
close c
deallocate c
select * from @Table order by pfad
GO
Nicht wirklich schön, geht aber...
Gruß
Norman
  Mit Zitat antworten Zitat