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/e9/e9d30b98ff9dc51d54a1b5dcf78...

120 lines
12 KiB

USE [Vertragsverwaltung_20160404]
GO
/****** Object: StoredProcedure [dbo].[sp_rpt_ikv] Script Date: 02.12.2016 09:08:53 ******/
DROP PROCEDURE [dbo].[sp_rpt_ikv]
GO
/****** Object: StoredProcedure [dbo].[sp_rpt_ikv] 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 PROCEDURE [dbo].[sp_rpt_ikv]
@sqlwhere varchar(1024)
AS
BEGIN
SELECT TOP (100) PERCENT dbo.Applikation.ApplikationNr, dbo.Applikation.Bezeichnung, dbo.Applikation_IKV_Relevanztyp.Bezeichnung AS Geschaeftsrelevanz,
dbo.Applikation_IKV_Ausfalldauer.Bezeichnung AS Max_Ausfalldauer, dbo.Applikation.IKVProviderVereinbart AS IKV_Vereinbart,
dbo.Applikation_IKV_VereinbarteAusfalldauer.Bezeichnung AS Vereinbarte_Ausfalldauer, dbo.Applikation_IKV_LoesungTyp.Bezeichnung AS Loesungsart,
dbo.Applikation_IKV_Test.Durchgeführt AS IKV_Test_Durchgefuehrt, dbo.Applikation_IKV_TestResultat.Bezeichnung AS ikv_Test_Resultat,
dbo.Applikation_IKV_Test.Geplant AS ikv_test_geplant, dbo.Applikation_IKV_Test.Aktiv
into #tmpd
FROM dbo.Applikation_IKV_TestResultat INNER JOIN
dbo.Applikation_IKV_Test ON
dbo.Applikation_IKV_TestResultat.IKVTestResultatnr = dbo.Applikation_IKV_Test.Applikation_IKV_TestResultatNr RIGHT OUTER JOIN
dbo.Applikation ON dbo.Applikation_IKV_Test.ApplikationNr = dbo.Applikation.ApplikationNr LEFT OUTER JOIN
dbo.Applikation_IKV_LoesungTyp ON dbo.Applikation.IKVLoesungNr = dbo.Applikation_IKV_LoesungTyp.IKVLoesungTypnr LEFT OUTER JOIN
dbo.Applikation_IKV_VereinbarteAusfalldauer ON
dbo.Applikation.IKVProviderAussfalldauerNr = dbo.Applikation_IKV_VereinbarteAusfalldauer.IKVVereinbarteAusfalldauernr LEFT OUTER JOIN
dbo.Applikation_IKV_Ausfalldauer ON dbo.Applikation.IKVBizAusfalldauerNr = dbo.Applikation_IKV_Ausfalldauer.IKVAusfalldauernr LEFT OUTER JOIN
dbo.Applikation_IKV_Relevanztyp ON dbo.Applikation.IKVBizRelevanzNr = dbo.Applikation_IKV_Relevanztyp.IKVRelevanztypnr
WHERE (dbo.Applikation.Aktiv = 1)
alter table #tmpd add rowcounter integer
delete from #tmpd where aktiv=0
declare @anr INT
DECLARE @c int
DECLARE xc cursor FOR
SELECT ApplikationNr FROM #tmpd
OPEN xc
FETCH NEXT FROM xc INTO @anr
WHILE @@FETCH_STATUS=0 begin
SELECT @c=COUNT(*) FROM #tmpd WHERE ApplikationNr=@anr AND ikv_test_geplant IS NOT null
UPDATE #tmpd SET rowcounter=@c WHERE ApplikationNr=@anr
fetch NEXT FROM xc INTO @anr
END
CLOSE xc
DEALLOCATE xc
IF @sqlwhere='Geschaeftsrelevanz = ' + char(39) +'Ja'+CHAR(39) begin
select distinct * from #tmpd order by bezeichnung
END ELSE BEGIN
SELECT distinct * From #tmpd where not Geschaeftsrelevanz is null
end
return
--SELECT TOP (100) PERCENT dbo.applikation.ApplikationNr,dbo.Applikation.Bezeichnung, dbo.Applikation_IKV_Relevanztyp.Bezeichnung AS Geschaeftsrelevanz,
-- dbo.Applikation_IKV_Ausfalldauer.Bezeichnung AS Max_Ausfalldauer, isnull(dbo.Applikation.IKVProviderVereinbart,0) AS IKV_Vereinbart,
-- dbo.Applikation_IKV_VereinbarteAusfalldauer.Bezeichnung AS Vereinbarte_Ausfalldauer, dbo.Applikation_IKV_LoesungTyp.Bezeichnung AS Loesungsart,
-- dbo.applikation.Aktiv
--into #tmpd
--FROM dbo.Applikation LEFT OUTER JOIN
-- dbo.Applikation_IKV_LoesungTyp ON dbo.Applikation.IKVLoesungNr = dbo.Applikation_IKV_LoesungTyp.IKVLoesungTypnr LEFT OUTER JOIN
-- dbo.Applikation_IKV_VereinbarteAusfalldauer ON
-- dbo.Applikation.IKVProviderAussfalldauerNr = dbo.Applikation_IKV_VereinbarteAusfalldauer.IKVVereinbarteAusfalldauernr LEFT OUTER JOIN
-- dbo.Applikation_IKV_Ausfalldauer ON dbo.Applikation.IKVBizAusfalldauerNr = dbo.Applikation_IKV_Ausfalldauer.IKVAusfalldauernr LEFT OUTER JOIN
-- dbo.Applikation_IKV_Relevanztyp ON dbo.Applikation.IKVBizRelevanzNr = dbo.Applikation_IKV_Relevanztyp.IKVRelevanztypnr
--where dbo.applikation.Aktiv=1
--alter table #tmpd add IKV_Test_Durchgefuehrt datetime null
--alter table #tmpd add ikv_Test_Resultat varchar(255) null
--alter table #tmpd add ikv_test_geplant datetime null
--declare @anr int
--declare @durchgefuehrt datetime
--declare @resultat datetime
--declare @resultattext varchar(255)
--declare xc cursor for
-- select applikationnr from #tmpd
--open xc
--fetch next from xc into @anr
--while @@FETCH_STATUS=0 begin
-- set @durchgefuehrt = CONVERT(DATETIME, '1900-01-01 00:00:00', 102)
-- select top 1 @durchgefuehrt=durchgeführt, @resultat=Applikation_IKV_TestResultatNr from Applikation_IKV_Test where ApplikationNr=@anr and Aktiv=1 order by Durchgeführt desc
-- if @durchgefuehrt > CONVERT(DATETIME, '1900-01-01 00:00:00', 102) begin
-- select @resultattext=bezeichnung from Applikation_IKV_TestResultat where Applikation_IKV_TestResultat.IKVTestResultatnr=@resultat
-- update #tmpd set IKV_Test_Durchgefuehrt=@durchgefuehrt, ikv_Test_Resultat=@resultattext where applikationnr=@anr
-- end
-- set @durchgefuehrt = CONVERT(DATETIME, '1900-01-01 00:00:00', 102)
-- select top 1 @durchgefuehrt=geplant from Applikation_IKV_Test where ApplikationNr=@anr and Aktiv=1
-- and durchgeführt=CONVERT(DATETIME, '1900-01-01 00:00:00',102) order by Geplant desc
-- if @durchgefuehrt > CONVERT(DATETIME, '1900-01-01 00:00:00', 102) begin
-- update #tmpd set ikv_test_geplant=@durchgefuehrt where applikationnr=@anr
-- end
-- fetch next from xc into @anr
--end
--close xc
--deallocate xc
--IF @sqlwhere='Geschaeftsrelevanz = ' + char(39) +'Ja'+CHAR(39) begin
-- select distinct * from #tmpd where bezeichnung<>'' order by bezeichnung
--END ELSE BEGIN
-- SELECT distinct * From #tmpd where not Geschaeftsrelevanz is null
--end
END
GO