USE [Vertragsverwaltung_20160404] GO /****** Object: StoredProcedure [dbo].[my_servicekatalog_struktur_up] Script Date: 02.12.2016 09:08:54 ******/ DROP PROCEDURE [dbo].[my_servicekatalog_struktur_up] GO /****** Object: StoredProcedure [dbo].[my_servicekatalog_struktur_up] Script Date: 02.12.2016 09:08:54 ******/ SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE proc [dbo].[my_servicekatalog_struktur_up] @Root int, @imandant int AS BEGIN SET NOCOUNT ON declare @katalogid int, @bezeichnung varchar(50), @nr int, @parent int, @seclevel int, @aktiv bit select @bezeichnung=bezeichnung_intern, @nr=servicekatalognr, @parent=parentid, @seclevel=securitylevelnr, @aktiv=aktiv from servicekatalog where servicekatalognr=@root and mandantnr=@imandant print @bezeichnung insert into #tmpd (servicekatalognr, bezeichnung, parentid,securitylevelnr, aktiv) values (@nr, @bezeichnung, @parent,@seclevel,@aktiv) print @parent print '---' set @katalogid=(select parentid from servicekatalog where servicekatalognr=@nr) while @katalogid is not null begin exec dbo.my_servicekatalog_struktur_up @katalogid, 1 set @katalogid=(select parentid from dbo.servicekatalog where servicekatalognr = @nr and parentid>@katalogid) end end GO