SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'WGP_Servidor_GetInfo') )
DROP PROCEDURE WGP_Servidor_GetInfo
GO

CREATE PROCEDURE WGP_Servidor_GetInfo
AS
BEGIN
	
	SELECT id_datos, LTRIM(RTRIM(descripcion)) FROM datos WHERE id_modulo = 1

	RETURN

END
GO

---------------------------------------------------------------------------------
---------------------------------------------------------------------------------

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'WGP_Servicios_GetInfo') )
DROP PROCEDURE WGP_Servicios_GetInfo
GO

CREATE PROCEDURE WGP_Servicios_GetInfo
	@id_server  INT,
	@id_datos INT
AS
BEGIN

	SELECT I.id_serv, LTRIM(RTRIM(IC.descripcion)), I.automatico, I.manual FROM IcsTermServ I 
	INNER JOIN IcsServices IC on IC.id_serv = I.id_serv
	WHERE id_server = @id_server AND id_datos = @id_datos

	RETURN

END
GO

---------------------------------------------------------------------------------
---------------------------------------------------------------------------------

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'WGP_Servicios_PutInfo') )
DROP PROCEDURE WGP_Servicios_PutInfo
GO

CREATE PROCEDURE WGP_Servicios_PutInfo
	@id_server INT,
	@id_datos INT,
	@id_serv INT,
	@automatico BIT,
	@manual BIT
AS
BEGIN
	DECLARE @MensajeError VARCHAR(255) = ''
	
			-- Editar
		
			UPDATE IcsTermServ
			SET automatico = @automatico,
			    manual = @manual
			WHERE id_server = @id_server AND id_datos = @id_datos AND id_serv = @id_serv

	SELECT @id_server AS Id
	
	RETURN

	ERROR:
		RAISERROR (@MensajeError, 16, 1)

END
GO