IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_syn_puntoIntegracionTabla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_syn_puntoIntegracionTabla]
GO
CREATE PROCEDURE [reg_syn_puntoIntegracionTabla]
	@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],
		[puntoIntegracionTabla] AS [puntoIntegracionTabla],
		[puntoIntegracionTabla_codigo] AS [puntoIntegracionTabla_codigo],
		[id_puntoIntegracion] AS [id_puntoIntegracion],
		[tabla] AS [tabla]
	FROM [syn_puntoIntegracionTabla]
	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_puntoIntegracionTabla]')) DROP VIEW [dbo].[view_syn_puntoIntegracionTabla]
GO
CREATE  VIEW [view_syn_puntoIntegracionTabla] AS
SELECT 	[syn_puntoIntegracionTabla].[id] AS [id],
		[syn_puntoIntegracionTabla].[uid] AS [uid],
		[syn_puntoIntegracionTabla].[eid] AS [eid],
		[syn_puntoIntegracionTabla].[id_usuario_modifico] AS [id_usuario_modifico],
		[syn_puntoIntegracionTabla].[id_usuario_creo] AS [id_usuario_creo],
		[syn_puntoIntegracionTabla].[fechaModificacion] AS [fechaModificacion],
		[syn_puntoIntegracionTabla].[fechaCreacion] AS [fechaCreacion],
		[syn_puntoIntegracionTabla].[active] AS [active],
		[syn_puntoIntegracionTabla].[puntoIntegracionTabla] AS [puntoIntegracionTabla],
		[syn_puntoIntegracionTabla].[puntoIntegracionTabla_codigo] AS [puntoIntegracionTabla_codigo],
		[syn_puntoIntegracionTabla].[id_puntoIntegracion] AS [id_puntoIntegracion],
[syn_puntoIntegracion].[puntoIntegracion] as [syn_puntoIntegracion_puntoIntegracion],
[syn_puntoIntegracion].[puntoIntegracion_codigo] as [syn_puntoIntegracion_puntoIntegracion_codigo],
[syn_puntoIntegracion].[tablaLocal] as [syn_puntoIntegracion_tablaLocal],
[syn_puntoIntegracion].[condicion] as [syn_puntoIntegracion_condicion],
[syn_puntoIntegracion].[urlConsumir] as [syn_puntoIntegracion_urlConsumir],
[syn_puntoIntegracion].[id_puntoIntegracion] as [syn_puntoIntegracion_id_puntoIntegracion],
[syn_puntoIntegracion].[id_sistemaIntegrar] as [syn_puntoIntegracion_id_sistemaIntegrar],
[syn_puntoIntegracion].[metodo] as [syn_puntoIntegracion_metodo],
		[syn_puntoIntegracionTabla].[tabla] AS [tabla],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [syn_puntoIntegracionTabla]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[syn_puntoIntegracionTabla].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[syn_puntoIntegracionTabla].[id_usuario_creo]
	INNER JOIN [syn_puntoIntegracion] ON [syn_puntoIntegracion].id=[syn_puntoIntegracionTabla].[id_puntoIntegracion]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [syn_puntoIntegracionTabla].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [syn_puntoIntegracionTabla].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_puntoIntegracionTablasXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_puntoIntegracionTablasXusuario_modifico]
GO
CREATE PROCEDURE [sel_syn_puntoIntegracionTablasXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_syn_puntoIntegracionTabla]
	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_puntoIntegracionTablasXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_puntoIntegracionTablasXusuario_creo]
GO
CREATE PROCEDURE [sel_syn_puntoIntegracionTablasXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_syn_puntoIntegracionTabla]
	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_puntoIntegracionTablasXpuntoIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_puntoIntegracionTablasXpuntoIntegracion]
GO
CREATE PROCEDURE [sel_syn_puntoIntegracionTablasXpuntoIntegracion]
	@p_id_puntoIntegracion INT
AS
BEGIN
	SELECT * 
	FROM [view_syn_puntoIntegracionTabla]
	WHERE ([id_puntoIntegracion]= @p_id_puntoIntegracion)
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_puntoIntegracionTablas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_puntoIntegracionTablas]
GO
CREATE PROCEDURE [sel_syn_puntoIntegracionTablas]
	
	@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_puntoIntegracionTabla]
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_puntoIntegracionTablas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_syn_puntoIntegracionTablas]
GO
CREATE PROCEDURE [lis_syn_puntoIntegracionTablas]
	AS
BEGIN
	SELECT id AS id,
[puntoIntegracionTabla] AS [syn_puntoIntegracionTabla]
	FROM [syn_puntoIntegracionTabla]
	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_puntoIntegracionTabla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_syn_puntoIntegracionTabla]
GO
CREATE PROCEDURE [upd_syn_puntoIntegracionTabla]
	@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_puntoIntegracionTabla varchar(300) = null,
		@p_puntoIntegracionTabla_codigo varchar(100) = null,
		@p_id_puntoIntegracion int = null,
		@p_tabla varchar(200) = null
AS
BEGIN
		UPDATE [syn_puntoIntegracionTabla]
		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(),
			[puntoIntegracionTabla] = isnull(@p_puntoIntegracionTabla,[puntoIntegracionTabla]),
			[puntoIntegracionTabla_codigo] = isnull(@p_puntoIntegracionTabla_codigo,[puntoIntegracionTabla_codigo]),
			[id_puntoIntegracion] = isnull(@p_id_puntoIntegracion,[id_puntoIntegracion]),
			[tabla] = isnull(@p_tabla,[tabla])
		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_puntoIntegracionTabla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_syn_puntoIntegracionTabla]
GO
CREATE PROCEDURE [ins_syn_puntoIntegracionTabla]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_puntoIntegracionTabla varchar(300),
		@p_puntoIntegracionTabla_codigo varchar(100),
		@p_id_puntoIntegracion int,
		@p_tabla varchar(200)
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [syn_puntoIntegracionTabla]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[puntoIntegracionTabla],
			[puntoIntegracionTabla_codigo],
			[id_puntoIntegracion],
			[tabla])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_puntoIntegracionTabla,
			@p_puntoIntegracionTabla_codigo,
			@p_id_puntoIntegracion,
			@p_tabla)
		SET @v_id = scope_identity()
UPDATE [syn_puntoIntegracionTabla] 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_puntoIntegracionTabla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_syn_puntoIntegracionTabla]
GO
CREATE PROCEDURE [act_syn_puntoIntegracionTabla]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [syn_puntoIntegracionTabla]
	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_puntoIntegracionTabla_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_syn_puntoIntegracionTabla_m]
GO
CREATE PROCEDURE [reg_syn_puntoIntegracionTabla_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],
		[puntoIntegracionTabla] AS [puntoIntegracionTabla],
		[puntoIntegracionTabla_codigo] AS [puntoIntegracionTabla_codigo],
		[id_puntoIntegracion] AS [id_puntoIntegracion],
		[tabla] AS [tabla]
	FROM [syn_puntoIntegracionTabla]
	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_puntoIntegracionTablasXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_puntoIntegracionTablasXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_syn_puntoIntegracionTablasXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_syn_puntoIntegracionTabla]
	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_puntoIntegracionTablasXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_puntoIntegracionTablasXusuario_creo_m]
GO
CREATE PROCEDURE [sel_syn_puntoIntegracionTablasXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_syn_puntoIntegracionTabla]
	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_puntoIntegracionTablasXpuntoIntegracion_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_puntoIntegracionTablasXpuntoIntegracion_m]
GO
CREATE PROCEDURE [sel_syn_puntoIntegracionTablasXpuntoIntegracion_m]
	@p_id_puntoIntegracion INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_syn_puntoIntegracionTabla]
	WHERE ([id_puntoIntegracion]= @p_id_puntoIntegracion)
	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_puntoIntegracionTablas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_puntoIntegracionTablas_m]
GO
CREATE PROCEDURE [sel_syn_puntoIntegracionTablas_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_puntoIntegracionTabla]
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_puntoIntegracionTablas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_syn_puntoIntegracionTablas_m]
GO
CREATE PROCEDURE [lis_syn_puntoIntegracionTablas_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[puntoIntegracionTabla] AS [syn_puntoIntegracionTabla]
	FROM [syn_puntoIntegracionTabla]
	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_puntoIntegracionTabla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_syn_puntoIntegracionTabla]
GO
CREATE PROCEDURE [aud_syn_puntoIntegracionTabla]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [syn_puntoIntegracionTabla].id as id_tabla,
	[syn_puntoIntegracionTabla].id_usuario_modifico as id_usuario_modifico,
	[syn_puntoIntegracionTabla].id_usuario_creo as id_usuario_creo,
	[syn_puntoIntegracionTabla].fechaModificacion as fechaModificacion,
	[syn_puntoIntegracionTabla].fechaCreacion as fechaCreacion,
	[syn_puntoIntegracionTabla].active as active,
	[syn_puntoIntegracionTabla].[puntoIntegracionTabla] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [syn_puntoIntegracionTabla]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[syn_puntoIntegracionTabla].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[syn_puntoIntegracionTabla].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'syn_puntoIntegracionTabla'
-----------------------------------26/04/21 21:04:37