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.
127 lines
6.8 KiB
127 lines
6.8 KiB
USE [Vertragsverwaltung_20160404]
|
|
GO
|
|
/****** Object: StoredProcedure [dbo].[sp_Auswertung_Get_Auswertungen] Script Date: 02.12.2016 09:08:54 ******/
|
|
DROP PROCEDURE [dbo].[sp_Auswertung_Get_Auswertungen]
|
|
GO
|
|
/****** Object: StoredProcedure [dbo].[sp_Auswertung_Get_Auswertungen] Script Date: 02.12.2016 09:08:55 ******/
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
-- =============================================
|
|
-- Author: <Author,,Name>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
CREATE proc [dbo].[sp_Auswertung_Get_Auswertungen]
|
|
@mitarbeiternr int
|
|
as
|
|
CREATE TABLE #tmpd(
|
|
|
|
[ID] [int] ,
|
|
|
|
[bezeichnung] [varchar] (255) null,
|
|
|
|
[parentid] [int] null,
|
|
|
|
[Auswertungnr] [int],
|
|
|
|
[beschreibung] [varchar] (1024) null
|
|
|
|
) ON [DEFAULT]
|
|
|
|
|
|
|
|
declare @id int
|
|
|
|
declare @gnr int
|
|
|
|
declare @anr int
|
|
|
|
declare @bez varchar(255)
|
|
|
|
declare @pid int
|
|
|
|
declare @gnr1 int
|
|
|
|
declare @gbez varchar(255)
|
|
|
|
declare @cnt int
|
|
|
|
declare @besch varchar(1024)
|
|
|
|
set @id=1000
|
|
|
|
declare xc cursor for
|
|
|
|
SELECT DISTINCT dbo.auswertunggruppeauswertung.auswertunggruppenr as auswertunggruppenr, dbo.auswertung.auswertungnr,
|
|
|
|
dbo.auswertung.bezeichnung as auswertung, dbo.auswertung.beschreibung
|
|
|
|
FROM dbo.AuswertungGruppe INNER JOIN
|
|
|
|
dbo.funktionsgruppe_auswertungGruppe ON dbo.AuswertungGruppe.AuswertungGruppeNr = dbo.funktionsgruppe_auswertungGruppe.AuswertungGruppeNr INNER JOIN
|
|
|
|
dbo.funktionsgruppe ON dbo.funktionsgruppe_auswertungGruppe.funktionsgruppenr = dbo.funktionsgruppe.funktionsgruppenr INNER JOIN
|
|
|
|
dbo.mitarbeiter_funktionsgruppe ON dbo.funktionsgruppe.funktionsgruppenr = dbo.mitarbeiter_funktionsgruppe.funktionsgruppenr INNER JOIN
|
|
|
|
dbo.AuswertungGruppeAuswertung ON dbo.AuswertungGruppe.AuswertungGruppeNr = dbo.AuswertungGruppeAuswertung.AuswertungGruppeNr INNER JOIN
|
|
|
|
dbo.Auswertung ON dbo.AuswertungGruppeAuswertung.AuswertungNr = dbo.Auswertung.AuswertungNr
|
|
|
|
WHERE (dbo.AuswertungGruppe.Aktiv = 1) AND (dbo.funktionsgruppe_auswertungGruppe.Aktiv = 1) AND (dbo.funktionsgruppe.aktiv = 1) AND
|
|
|
|
(dbo.mitarbeiter_funktionsgruppe.aktiv = 1) AND (dbo.AuswertungGruppeAuswertung.Aktiv = 1) AND (dbo.Auswertung.Aktiv = 1) AND
|
|
|
|
(dbo.mitarbeiter_funktionsgruppe.mitarbeiternr = @mitarbeiternr)
|
|
|
|
open xc
|
|
|
|
fetch next from xc into @gnr, @anr, @bez, @besch
|
|
|
|
while @@fetch_status=0 begin
|
|
|
|
set @id=@id+1
|
|
|
|
insert #tmpd(id, bezeichnung, parentid, auswertungnr, beschreibung) values (@id, @bez, @gnr, @anr, @besch)
|
|
|
|
|
|
|
|
set @pid=@gnr
|
|
|
|
while @pid>0 begin
|
|
|
|
select @gnr1=auswertunggruppenr, @gbez=bezeichnung, @pid=parentid from auswertunggruppe where auswertunggruppenr=@gnr
|
|
|
|
select @cnt=count(*) from #tmpd where id=@gnr1
|
|
|
|
if @cnt=0 insert #tmpd(id, bezeichnung, parentid, auswertungnr, beschreibung) values (@gnr1,@gbez,@pid,0,'')
|
|
|
|
set @gnr=@pid
|
|
|
|
end
|
|
|
|
fetch next from xc into @gnr, @anr, @bez, @besch
|
|
|
|
end
|
|
|
|
close xc
|
|
|
|
deallocate xc
|
|
|
|
insert #tmpd (id, bezeichnung, parentid, auswertungnr, beschreibung) values (0, 'root',null,null,null)
|
|
|
|
select * from #tmpd order by bezeichnung
|
|
|
|
drop table #tmpd
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
GO
|