IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_doc_documentoAtributo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_documentoAtributo]
GO
CREATE PROCEDURE [reg_doc_documentoAtributo]
	@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],
		[documentoAtributo] AS [documentoAtributo],
		[documentoAtributo_codigo] AS [documentoAtributo_codigo],
		[id_documento] AS [id_documento],
		[id_atributo] AS [id_atributo],
		[id_opcionAtributo] AS [id_opcionAtributo]
	FROM [doc_documentoAtributo]
	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_doc_documentoAtributo]')) DROP VIEW [dbo].[view_doc_documentoAtributo]
GO
CREATE  VIEW [view_doc_documentoAtributo] AS
SELECT 	[doc_documentoAtributo].[id] AS [id],
		[doc_documentoAtributo].[uid] AS [uid],
		[doc_documentoAtributo].[eid] AS [eid],
		[doc_documentoAtributo].[id_usuario_modifico] AS [id_usuario_modifico],
		[doc_documentoAtributo].[id_usuario_creo] AS [id_usuario_creo],
		[doc_documentoAtributo].[fechaModificacion] AS [fechaModificacion],
		[doc_documentoAtributo].[fechaCreacion] AS [fechaCreacion],
		[doc_documentoAtributo].[active] AS [active],
		[doc_documentoAtributo].[documentoAtributo] AS [documentoAtributo],
		[doc_documentoAtributo].[documentoAtributo_codigo] AS [documentoAtributo_codigo],
		[doc_documentoAtributo].[id_documento] AS [id_documento],
[doc_documento].[documento] as [doc_documento_documento],
[doc_documento].[documento_codigo] as [doc_documento_documento_codigo],
[doc_documento].[documento_numero] as [doc_documento_documento_numero],
[doc_documento].[prefijo] as [doc_documento_prefijo],
[doc_documento].[subtotal] as [doc_documento_subtotal],
[doc_documento].[descuento] as [doc_documento_descuento],
[doc_documento].[iva] as [doc_documento_iva],
[doc_documento].[total] as [doc_documento_total],
[doc_documento].[costo] as [doc_documento_costo],
[doc_documento].[rentabilidad] as [doc_documento_rentabilidad],
[doc_documento].[trm] as [doc_documento_trm],
[doc_documento].[fecha_fh] as [doc_documento_fecha_fh],
[doc_documento].[fechaSugerida_fh] as [doc_documento_fechaSugerida_fh],
[doc_documento].[fechaCierre_ff] as [doc_documento_fechaCierre_ff],
[doc_documento].[fechaLimite_fh] as [doc_documento_fechaLimite_fh],
[doc_documento].[id_subtipoDocumento] as [doc_documento_id_subtipoDocumento],
[doc_documento].[id_tercero_cliente] as [doc_documento_id_tercero_cliente],
[doc_documento].[id_documento] as [doc_documento_id_documento],
[doc_documento].[id_tercero_proveedor] as [doc_documento_id_tercero_proveedor],
[doc_documento].[id_prioridadDocumento] as [doc_documento_id_prioridadDocumento],
[doc_documento].[id_moneda] as [doc_documento_id_moneda],
[doc_documento].[id_estadoTipoDocumento] as [doc_documento_id_estadoTipoDocumento],
[doc_documento].[id_motivoestado] as [doc_documento_id_motivoestado],
[doc_documento].[subtotalPlaneado] as [doc_documento_subtotalPlaneado],
[doc_documento].[descuentoPlaneado] as [doc_documento_descuentoPlaneado],
[doc_documento].[ivaPlaneado] as [doc_documento_ivaPlaneado],
[doc_documento].[totalPlaneado] as [doc_documento_totalPlaneado],
[doc_documento].[costoPlaneado] as [doc_documento_costoPlaneado],
[doc_documento].[id_usuario_asignado] as [doc_documento_id_usuario_asignado],
[doc_documento].[id_usuario_enUso] as [doc_documento_id_usuario_enUso],
		[doc_documentoAtributo].[id_atributo] AS [id_atributo],
[cat_atributo].[atributo] as [cat_atributo_atributo],
[cat_atributo].[atributo_codigo] as [cat_atributo_atributo_codigo],
[cat_atributo].[nombreControl] as [cat_atributo_nombreControl],
[cat_atributo].[esVariable] as [cat_atributo_esVariable],
[cat_atributo].[resaltado] as [cat_atributo_resaltado],
[cat_atributo].[valorMinimo] as [cat_atributo_valorMinimo],
[cat_atributo].[ValorMaximo] as [cat_atributo_ValorMaximo],
[cat_atributo].[id_seccionAtributo] as [cat_atributo_id_seccionAtributo],
[cat_atributo].[id_tipoAtributo] as [cat_atributo_id_tipoAtributo],
[cat_atributo].[id_unidad] as [cat_atributo_id_unidad],
[cat_atributo].[esObligatorio] as [cat_atributo_esObligatorio],
		[doc_documentoAtributo].[id_opcionAtributo] AS [id_opcionAtributo],
[equ_opcionAtributo].[opcionAtributo] as [equ_opcionAtributo_opcionAtributo],
[equ_opcionAtributo].[opcionAtributo_codigo] as [equ_opcionAtributo_opcionAtributo_codigo],
[equ_opcionAtributo].[orden] as [equ_opcionAtributo_orden],
[equ_opcionAtributo].[id_atributo] as [equ_opcionAtributo_id_atributo],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [doc_documentoAtributo]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_documentoAtributo].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_documentoAtributo].[id_usuario_creo]
	INNER JOIN [doc_documento] ON [doc_documento].id=[doc_documentoAtributo].[id_documento]
	INNER JOIN [cat_atributo] ON [cat_atributo].id=[doc_documentoAtributo].[id_atributo]
	INNER JOIN [equ_opcionAtributo] ON [equ_opcionAtributo].id=[doc_documentoAtributo].[id_opcionAtributo]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [doc_documentoAtributo].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [doc_documentoAtributo].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_doc_documentoAtributosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXusuario_modifico]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoAtributo]
	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_doc_documentoAtributosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXusuario_creo]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoAtributo]
	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_doc_documentoAtributosXdocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXdocumento]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXdocumento]
	@p_id_documento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoAtributo]
	WHERE ([id_documento]= @p_id_documento)
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_doc_documentoAtributosXatributo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXatributo]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXatributo]
	@p_id_atributo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoAtributo]
	WHERE ([id_atributo]= @p_id_atributo)
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_doc_documentoAtributosXopcionAtributo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXopcionAtributo]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXopcionAtributo]
	@p_id_opcionAtributo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoAtributo]
	WHERE ([id_opcionAtributo]= @p_id_opcionAtributo)
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_doc_documentoAtributos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributos]
GO
CREATE PROCEDURE [sel_doc_documentoAtributos]
	
	@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_doc_documentoAtributo]
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_doc_documentoAtributos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_documentoAtributos]
GO
CREATE PROCEDURE [lis_doc_documentoAtributos]
	AS
BEGIN
	SELECT id AS id,
[documentoAtributo] AS [doc_documentoAtributo]
	FROM [doc_documentoAtributo]
	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_doc_documentoAtributo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_doc_documentoAtributo]
GO
CREATE PROCEDURE [upd_doc_documentoAtributo]
	@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_documentoAtributo varchar(8000) = null,
		@p_documentoAtributo_codigo varchar(100) = null,
		@p_id_documento int = null,
		@p_id_atributo int = null,
		@p_id_opcionAtributo int = null
AS
BEGIN
		UPDATE [doc_documentoAtributo]
		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(),
			[documentoAtributo] = isnull(@p_documentoAtributo,[documentoAtributo]),
			[documentoAtributo_codigo] = isnull(@p_documentoAtributo_codigo,[documentoAtributo_codigo]),
			[id_documento] = isnull(@p_id_documento,[id_documento]),
			[id_atributo] = isnull(@p_id_atributo,[id_atributo]),
			[id_opcionAtributo] = isnull(@p_id_opcionAtributo,[id_opcionAtributo])
		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_doc_documentoAtributo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_doc_documentoAtributo]
GO
CREATE PROCEDURE [ins_doc_documentoAtributo]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_documentoAtributo varchar(8000),
		@p_documentoAtributo_codigo varchar(100),
		@p_id_documento int,
		@p_id_atributo int,
		@p_id_opcionAtributo int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [doc_documentoAtributo]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[documentoAtributo],
			[documentoAtributo_codigo],
			[id_documento],
			[id_atributo],
			[id_opcionAtributo])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_documentoAtributo,
			@p_documentoAtributo_codigo,
			@p_id_documento,
			@p_id_atributo,
			@p_id_opcionAtributo)
		SET @v_id = scope_identity()
UPDATE [doc_documentoAtributo] 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_doc_documentoAtributo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_doc_documentoAtributo]
GO
CREATE PROCEDURE [act_doc_documentoAtributo]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [doc_documentoAtributo]
	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_doc_documentoAtributo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_documentoAtributo_m]
GO
CREATE PROCEDURE [reg_doc_documentoAtributo_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],
		[documentoAtributo] AS [documentoAtributo],
		[documentoAtributo_codigo] AS [documentoAtributo_codigo],
		[id_documento] AS [id_documento],
		[id_atributo] AS [id_atributo],
		[id_opcionAtributo] AS [id_opcionAtributo]
	FROM [doc_documentoAtributo]
	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_doc_documentoAtributosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoAtributo]
	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_doc_documentoAtributosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoAtributo]
	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_doc_documentoAtributosXdocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXdocumento_m]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXdocumento_m]
	@p_id_documento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoAtributo]
	WHERE ([id_documento]= @p_id_documento)
	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_doc_documentoAtributosXatributo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXatributo_m]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXatributo_m]
	@p_id_atributo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoAtributo]
	WHERE ([id_atributo]= @p_id_atributo)
	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_doc_documentoAtributosXopcionAtributo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributosXopcionAtributo_m]
GO
CREATE PROCEDURE [sel_doc_documentoAtributosXopcionAtributo_m]
	@p_id_opcionAtributo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoAtributo]
	WHERE ([id_opcionAtributo]= @p_id_opcionAtributo)
	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_doc_documentoAtributos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoAtributos_m]
GO
CREATE PROCEDURE [sel_doc_documentoAtributos_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_doc_documentoAtributo]
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_doc_documentoAtributos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_documentoAtributos_m]
GO
CREATE PROCEDURE [lis_doc_documentoAtributos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[documentoAtributo] AS [doc_documentoAtributo]
	FROM [doc_documentoAtributo]
	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_doc_documentoAtributo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_doc_documentoAtributo]
GO
CREATE PROCEDURE [aud_doc_documentoAtributo]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [doc_documentoAtributo].id as id_tabla,
	[doc_documentoAtributo].id_usuario_modifico as id_usuario_modifico,
	[doc_documentoAtributo].id_usuario_creo as id_usuario_creo,
	[doc_documentoAtributo].fechaModificacion as fechaModificacion,
	[doc_documentoAtributo].fechaCreacion as fechaCreacion,
	[doc_documentoAtributo].active as active,
	[doc_documentoAtributo].[documentoAtributo] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [doc_documentoAtributo]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_documentoAtributo].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_documentoAtributo].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'doc_documentoAtributo'
-----------------------------------14/09/2017 12:42:17