
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_syn_sistemaIntegrar]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_syn_sistemaIntegrar]
GO
CREATE PROCEDURE [reg_syn_sistemaIntegrar]
	@p_id INT
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[sistemaIntegrar] AS [sistemaIntegrar],
		[sistemaIntegrar_codigo] AS [sistemaIntegrar_codigo],
		[usuario] AS [usuario],
		[clave] AS [clave]
	FROM [syn_sistemaIntegrar]
	WHERE	(id = @p_id)

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_syn_sistemaIntegrar]')) DROP VIEW [dbo].[view_syn_sistemaIntegrar]
GO
CREATE  VIEW [view_syn_sistemaIntegrar] AS
SELECT 	[syn_sistemaIntegrar].[id] AS [id],
		[syn_sistemaIntegrar].[uid] AS [uid],
		[syn_sistemaIntegrar].[eid] AS [eid],
		[syn_sistemaIntegrar].[id_usuario_modifico] AS [id_usuario_modifico],
		[syn_sistemaIntegrar].[id_usuario_creo] AS [id_usuario_creo],
		[syn_sistemaIntegrar].[fechaModificacion] AS [fechaModificacion],
		[syn_sistemaIntegrar].[fechaCreacion] AS [fechaCreacion],
		[syn_sistemaIntegrar].[active] AS [active],
		[syn_sistemaIntegrar].[sistemaIntegrar] AS [sistemaIntegrar],
		[syn_sistemaIntegrar].[sistemaIntegrar_codigo] AS [sistemaIntegrar_codigo],
		[syn_sistemaIntegrar].[usuario] AS [usuario],
		[syn_sistemaIntegrar].[clave] AS [clave],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [syn_sistemaIntegrar]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[syn_sistemaIntegrar].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[syn_sistemaIntegrar].[id_usuario_creo]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [syn_sistemaIntegrar].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [syn_sistemaIntegrar].active=1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_syn_sistemaIntegraresXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_sistemaIntegraresXusuario_modifico]
GO
CREATE PROCEDURE [sel_syn_sistemaIntegraresXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_syn_sistemaIntegrar]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_syn_sistemaIntegraresXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_sistemaIntegraresXusuario_creo]
GO
CREATE PROCEDURE [sel_syn_sistemaIntegraresXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_syn_sistemaIntegrar]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_syn_sistemaIntegrares]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_sistemaIntegrares]
GO
CREATE PROCEDURE [sel_syn_sistemaIntegrares]
	
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_syn_sistemaIntegrar]
WHERE (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_syn_sistemaIntegrares]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_syn_sistemaIntegrares]
GO
CREATE PROCEDURE [lis_syn_sistemaIntegrares]
	AS
BEGIN
	SELECT id AS id,
[sistemaIntegrar] AS [syn_sistemaIntegrar]
	FROM [syn_sistemaIntegrar]
	WHERE active = 1
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[upd_syn_sistemaIntegrar]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_syn_sistemaIntegrar]
GO
CREATE PROCEDURE [upd_syn_sistemaIntegrar]
	@p_id int = null,
		@p_uid varchar(500) = null,
		@p_eid varchar(50) = null,
		@p_id_usuario_modifico int = null,
		@p_id_usuario_creo int = null,
		@p_fechaCreacion smalldatetime = null,
		@p_sistemaIntegrar varchar(300) = null,
		@p_sistemaIntegrar_codigo varchar(100) = null,
		@p_usuario varchar(200) = null,
		@p_clave varchar(200) = null
AS
BEGIN
		UPDATE [syn_sistemaIntegrar]
		SET	[uid] = isnull(@p_uid,[uid]),
			[eid] = isnull(@p_eid,[eid]),
			[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
			[id_usuario_creo] = isnull(@p_id_usuario_creo,[id_usuario_creo]),
			[fechaModificacion] = GETDATE(),
			[sistemaIntegrar] = isnull(@p_sistemaIntegrar,[sistemaIntegrar]),
			[sistemaIntegrar_codigo] = isnull(@p_sistemaIntegrar_codigo,[sistemaIntegrar_codigo]),
			[usuario] = isnull(@p_usuario,[usuario]),
			[clave] = isnull(@p_clave,[clave])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ins_syn_sistemaIntegrar]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_syn_sistemaIntegrar]
GO
CREATE PROCEDURE [ins_syn_sistemaIntegrar]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_sistemaIntegrar varchar(300),
		@p_sistemaIntegrar_codigo varchar(100),
		@p_usuario varchar(200),
		@p_clave varchar(200)
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [syn_sistemaIntegrar]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[sistemaIntegrar],
			[sistemaIntegrar_codigo],
			[usuario],
			[clave])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_sistemaIntegrar,
			@p_sistemaIntegrar_codigo,
			@p_usuario,
			@p_clave)
		SET @v_id = scope_identity()
UPDATE [syn_sistemaIntegrar] set [uid] = [uid] + '_' + convert(varchar(20),@v_id) where [id]=@v_id
SELECT @v_id as id
RETURN @v_id
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[act_syn_sistemaIntegrar]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_syn_sistemaIntegrar]
GO
CREATE PROCEDURE [act_syn_sistemaIntegrar]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [syn_sistemaIntegrar]
	SET active=@p_active,
	[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
	[fechaModificacion] = GETDATE()
	WHERE	(id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_syn_sistemaIntegrar_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_syn_sistemaIntegrar_m]
GO
CREATE PROCEDURE [reg_syn_sistemaIntegrar_m]
	@p_id INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[sistemaIntegrar] AS [sistemaIntegrar],
		[sistemaIntegrar_codigo] AS [sistemaIntegrar_codigo],
		[usuario] AS [usuario],
		[clave] AS [clave]
	FROM [syn_sistemaIntegrar]
	WHERE	(id = @p_id)
	AND	(eid LIKE @p_eid+'%')

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_syn_sistemaIntegraresXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_sistemaIntegraresXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_syn_sistemaIntegraresXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_syn_sistemaIntegrar]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_syn_sistemaIntegraresXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_sistemaIntegraresXusuario_creo_m]
GO
CREATE PROCEDURE [sel_syn_sistemaIntegraresXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_syn_sistemaIntegrar]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_syn_sistemaIntegrares_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_sistemaIntegrares_m]
GO
CREATE PROCEDURE [sel_syn_sistemaIntegrares_m]
	@p_eid as varchar (50)='',
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_syn_sistemaIntegrar]
WHERE  (eid like '''+@p_eid+'%'+''' ) AND (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_syn_sistemaIntegrares_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_syn_sistemaIntegrares_m]
GO
CREATE PROCEDURE [lis_syn_sistemaIntegrares_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[sistemaIntegrar] AS [syn_sistemaIntegrar]
	FROM [syn_sistemaIntegrar]
	WHERE active = 1
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[aud_syn_sistemaIntegrar]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_syn_sistemaIntegrar]
GO
CREATE PROCEDURE [aud_syn_sistemaIntegrar]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [syn_sistemaIntegrar].id as id_tabla,
	[syn_sistemaIntegrar].id_usuario_modifico as id_usuario_modifico,
	[syn_sistemaIntegrar].id_usuario_creo as id_usuario_creo,
	[syn_sistemaIntegrar].fechaModificacion as fechaModificacion,
	[syn_sistemaIntegrar].fechaCreacion as fechaCreacion,
	[syn_sistemaIntegrar].active as active,
	[syn_sistemaIntegrar].[sistemaIntegrar] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [syn_sistemaIntegrar]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[syn_sistemaIntegrar].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[syn_sistemaIntegrar].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'syn_sistemaIntegrar'
-----------------------------------14/08/2020 6:18:49 p. m.