You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ITSM/.svn/pristine/84/84023fc9ec8bf6e977800fed4c8...

150 lines
14 KiB

USE [Vertragsverwaltung_20160404]
GO
/****** Object: StoredProcedure [dbo].[sp_get_applstruktur_20100911] Script Date: 02.12.2016 09:08:53 ******/
DROP PROCEDURE [dbo].[sp_get_applstruktur_20100911]
GO
/****** Object: StoredProcedure [dbo].[sp_get_applstruktur_20100911] Script Date: 02.12.2016 09:08:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
-- =============================================
-- Author: <Stefan Hutter>
-- Create date: <13.01.2008>
-- Description: <Auslesen der Struktur (inkl. Kategorien) der Applikationsverwaltung anhand eines Suchbegriffs>
-- =============================================
CREATE PROCEDURE [dbo].[sp_get_applstruktur_20100911]
@mitarbeiternr int,
@nuraktive int=0,
@alphasort int=0
AS
CREATE TABLE #tmpd(
[applikationsnr] [int] ,
[bezeichnung] [varchar] (255) null,
[parentid] [int] null,
[SecurityLevelNr] [int] null,
[kategorienr] [int] null,
[lic] bit null,
[aktiv] [bit] null,
[Strukturelement] [bit] null,
) ON [DEFAULT]
-- Rootentry für die Treeaufbereitung in der Applikation
insert #tmpd (applikationsnr, bezeichnung, parentid, aktiv) values(0,'Root',null,1)
declare @appnr int
declare @appbez varchar(50)
declare @appprnt int
declare @anr int
declare @bez varchar(50)
declare @pid int
declare @snr int
declare @aktiv bit
declare @knr int
set @appprnt = -1
-----------------------------------------------------------------------------------------
-- Erster Loop über die Applikationen, welche den entsprechenden Suchbegriff beinhalten
-----------------------------------------------------------------------------------------
SELECT DISTINCT dbo.Applikation.ApplikationNr, dbo.Applikation.Bezeichnung, dbo.Applikation.ParentID, dbo.Applikation.SecurityLevelNr, dbo.Applikation.Aktiv
into #tmpx
FROM dbo.Applikation left outer join
dbo.ApplikationKontakt ON dbo.Applikation.ApplikationNr = dbo.ApplikationKontakt.Applikationnr left outer join
dbo.Person ON dbo.ApplikationKontakt.PersonNr = dbo.Person.PersonNr
if @nuraktive=1 begin
delete from #tmpx where aktiv<>1
end
if @nuraktive=0 begin
delete from #tmpx where aktiv<>0
end
declare xc cursor for
select * from #tmpx
-- select Applikationnr, bezeichnung, parentid, securitylevelnr, aktiv from applikation
-- where bezeichnung like @suchstring or kurzbeschreibung like @suchstring
open xc
fetch next from xc into @appnr, @appbez, @pid, @snr, @aktiv
while @@fetch_status=0 begin
--insert #tmpd(applikationsnr, bezeichnung, parentid, securitylevelnr, aktiv)
-- values (@appnr, @appbez, @pid ,@snr, @aktiv)
-----------------------------------------------------------------------------------------
-- Zweiter Loop über die Einträge der obesten Ebene der Applikationen
-----------------------------------------------------------------------------------------
declare yc cursor for
select applikationnr, bezeichnung, parentid, securitylevelnr, applikationkategorienr, aktiv from applikation
where applikationnr=@appnr
open yc
fetch next from yc into @anr, @bez, @pid, @snr, @knr, @aktiv
while @@fetch_status=0 begin
insert #tmpd(applikationsnr, bezeichnung, parentid, securitylevelnr, kategorienr, aktiv)
values (@anr, @bez, @appprnt, @snr, @knr, @aktiv)
-----------------------------------------------------------------------------------------
-- Je Applikation die untergeordneten Applikationen/Module auslesen
-----------------------------------------------------------------------------------------
--execute dbo.sp_get_applstruktur_down @anr,1, @anr
execute dbo.sp_get_applstruktur_up @anr,1
fetch next from yc into @anr, @bez, @pid, @snr, @knr, @aktiv
end
close yc
deallocate yc
set @appprnt = @appprnt - 1
fetch next from xc into @appnr, @appbez, @pid, @snr, @aktiv
end
close xc
deallocate xc
update #tmpd set kategorienr = (select applikationkategorienr*-1 from applikation where applikationnr=#tmpd.applikationsnr and #tmpd.parentid=0)
update #tmpd set parentid=kategorienr where kategorienr < 0
declare kc cursor for
SELECT distinct dbo.ApplikationKategorie.ApplikationKategorieNr, dbo.ApplikationKategorie.Bezeichnung
FROM dbo.Applikation inner join
dbo.ApplikationKategorie ON dbo.Applikation.ApplikationKategorieNr = dbo.ApplikationKategorie.ApplikationKategorieNr inner join
dbo.#tmpd ON dbo.Applikation.ApplikationNr = dbo.#tmpd.applikationsnr
open kc
fetch next from kc into @knr, @bez
while @@fetch_status=0 begin
insert #tmpd(applikationsnr, bezeichnung, parentid, securitylevelnr, aktiv)
values (@knr * -1, @bez, 0, 0, @aktiv)
fetch next from kc into @knr, @bez
end
close kc
deallocate kc
-----------------------------------------------------------------------------------------
-- Daten zurück geben und temporäre Tabelle löschen
-----------------------------------------------------------------------------------------
delete from #tmpd where kategorienr is null and parentid < 0 or applikationsnr is null
--delete from #tmpd where kategorienr is null and (parentid 0 or parentid is null)
insert #tmpd (applikationsnr, bezeichnung, parentid, aktiv) values(0,'Root',null,1)
update #tmpd set lic=0
update #tmpd set lic=NurLizenz from applikation where #tmpd.applikationsnr=applikation.applikationnr
update #tmpd set strukturelement=0
update #tmpd set Strukturelement = applikation.strukturelement from applikation where #tmpd.applikationsnr=applikation.applikationnr
if @alphasort = 1 begin
update #tmpd set parentid=0 where parentid<0
delete from #tmpd where applikationsnr < 0
if @nuraktive=0 begin
select distinct applikationsnr, bezeichnung, parentid, lic, aktiv, strukturelement from #tmpd where ltrim(bezeichnung) <> '' order by bezeichnung
end else begin
select distinct applikationsnr, bezeichnung, parentid, lic, aktiv, strukturelement from #tmpd where ltrim(bezeichnung) <> '' order by bezeichnung
end
--select distinct applikationsnr, bezeichnung, parentid, lic, aktiv from #tmpd order by bezeichnung
drop table #tmpd
return
end
if @nuraktive=0 begin
select distinct applikationsnr, bezeichnung, parentid, lic, aktiv, strukturelement from #tmpd where ltrim(bezeichnung) <> '' order by bezeichnung
end else begin
select distinct applikationsnr, bezeichnung, parentid, lic, aktiv, strukturelement from #tmpd where ltrim(bezeichnung) <> '' order by bezeichnung
end
drop table #tmpd
GO