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/21/21811ad3d5aa482c6029f803fa2...

208 lines
17 KiB

USE [Vertragsverwaltung_20160404]
GO
/****** Object: StoredProcedure [dbo].[sp_get_set_server_applikation] Script Date: 02.12.2016 09:08:53 ******/
DROP PROCEDURE [dbo].[sp_get_set_server_applikation]
GO
/****** Object: StoredProcedure [dbo].[sp_get_set_server_applikation] 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_get_set_server_applikation]
@serverapplnr INT = 0 ,
@servernr INT = 0 ,
@applnr INT = 0 ,
@bemerkung VARCHAR(1024) = '' ,
@mitarbeiternr INT = 0 ,
@fnkt INT
AS
BEGIN
DECLARE @tbl TABLE
(
Mainkey INTEGER ,
Parentid INTEGER ,
bezeichnung VARCHAR(255) ,
imageindex INTEGER
)
IF @fnkt = 1 -- Daten auslesen Server->Appl
BEGIN
SELECT TOP ( 100 ) PERCENT
dbo.Applikation.ApplikationNr ,
dbo.Applikation.Bezeichnung ,
dbo.Server_Applikation.ServerNr
,CASE WHEN server_applikation.aktiv=1 THEN 0 ELSE 1 end AS imageindex
FROM dbo.Applikation
INNER JOIN dbo.Server_Applikation ON dbo.Applikation.ApplikationNr = dbo.Server_Applikation.Applikationnr
WHERE server_applikation.servernr = @servernr
--AND server_applikation.aktiv = 1
ORDER BY Bezeichnung
END
IF @fnkt = 2
BEGIN
INSERT INTO [dbo].[Server_Applikation]
( [ServerNr] ,
[Applikationnr] ,
[Bemerkung] ,
[Aktiv] ,
[erstellt_am] ,
[mutiert_am] ,
[mutierer]
)
VALUES ( @servernr ,
@applnr ,
'' ,
1 ,
GETDATE() ,
GETDATE() ,
@mitarbeiternr
)
END
IF @fnkt = 3 -- Daten auslesen Server->Appl
BEGIN
INSERT @tbl
( Mainkey ,
Parentid ,
bezeichnung ,
imageindex
)
VALUES ( 0 ,
NULL ,
'Root' ,
1
)
--Umgebung
INSERT @tbl
( Mainkey ,
Parentid ,
bezeichnung ,
imageindex
)
SELECT DISTINCT
dbo.Server_Umgebung.Server_UmgebungNr * 100000 AS MainKey ,
0 AS Parentid ,
dbo.Server_Umgebung.Bezeichnung ,
0 AS ImageIndex
FROM dbo.Server_Inventar
INNER JOIN dbo.Server_Umgebung ON dbo.Server_Inventar.Server_UmgebungNr = dbo.Server_Umgebung.Server_UmgebungNr
INNER JOIN dbo.Server_Applikation ON dbo.Server_Inventar.ServerInventarNr = dbo.Server_Applikation.ServerNr
WHERE ( dbo.Server_Applikation.Applikationnr = @applnr )
AND ( dbo.Server_Applikation.Aktiv = 1 )
-- Server-Kategorie
INSERT @tbl
( Mainkey ,
Parentid ,
bezeichnung ,
imageindex
)
SELECT DISTINCT
dbo.Server_Kategorie.Server_KategorieNr
* 110000
+ dbo.Server_Inventar.Server_UmgebungNr AS MainKey ,
dbo.Server_Inventar.Server_UmgebungNr * 100000 AS Expr1 ,
dbo.Server_Kategorie.Bezeichnung ,
1 AS ImageIndex
FROM dbo.Server_Inventar
INNER JOIN dbo.Server_Kategorie ON dbo.Server_Inventar.Server_KategorieNr = dbo.Server_Kategorie.Server_KategorieNr
INNER JOIN dbo.Server_Applikation ON dbo.Server_Inventar.ServerInventarNr = dbo.Server_Applikation.ServerNr
WHERE ( dbo.Server_Applikation.Applikationnr = @applnr )
AND ( dbo.Server_Applikation.Aktiv = 1 )
-- Server
INSERT @tbl
( Mainkey ,
Parentid ,
bezeichnung ,
imageindex
)
SELECT DISTINCT
dbo.Server_Inventar.ServerInventarNr AS MainKey ,
dbo.Server_Inventar.Server_KategorieNr
* 110000
+ dbo.Server_Inventar.Server_UmgebungNr AS ParentID ,
dbo.Server_Inventar.Bezeichnung ,
CASE WHEN dbo.Server_Inventar.aktiv=1 THEN 2 ELSE 4 end AS imageindex
FROM dbo.Server_Inventar
INNER JOIN dbo.Server_Applikation ON dbo.Server_Inventar.ServerInventarNr = dbo.Server_Applikation.ServerNr
WHERE --( dbo.Server_Inventar.Aktiv = 1 )
--AND
( dbo.Server_Applikation.Applikationnr = @applnr )
AND ( dbo.Server_Applikation.Aktiv = 1 )
SELECT *
FROM @tbl
RETURN
SELECT TOP ( 100 ) PERCENT
dbo.Server_Inventar.ServerInventarNr ,
dbo.Server_Inventar.Bezeichnung AS Bezeichnung ,
dbo.Server_Applikation.Applikationnr
FROM dbo.Server_Applikation
INNER JOIN dbo.Server_Inventar ON dbo.Server_Applikation.ServerNr = dbo.Server_Inventar.ServerInventarNr
WHERE ( dbo.Server_Applikation.Applikationnr = @applnr )
AND server_applikation.aktiv = 1
ORDER BY Bezeichnung
END
IF @fnkt = 4
BEGIN
UPDATE dbo.Server_Applikation
SET aktiv = 0 ,
mutierer = @mitarbeiternr ,
mutiert_am = GETDATE()
WHERE servernr = @servernr
AND Applikationnr = @applnr
AND aktiv = 1
END
IF @fnkt = 5
BEGIN
UPDATE dbo.Server_Applikation
SET aktiv = 0 ,
mutierer = @mitarbeiternr ,
mutiert_am = GETDATE()
WHERE servernr = @servernr
AND aktiv = 1
END
IF @fnkt=6 BEGIN
UPDATE dbo.Server_Applikation
SET aktiv = 1 ,
mutierer = @mitarbeiternr ,
mutiert_am = GETDATE()
WHERE Server_ApplikationNr=@serverapplnr
end
if @fnkt=7 begin
select count(*) from server_applikation
where applikationnr=@applnr and servernr=@servernr and aktiv=1
end
END
GO