

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_gen_localizacion_itemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gen_localizacion_itemDocumento]
GO
CREATE PROCEDURE [reg_gen_localizacion_itemDocumento]
	@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],
		[localizacion_itemDocumento] AS [localizacion_itemDocumento],
		[id_localizacion] AS [id_localizacion],
		[id_itemDocumento] AS [id_itemDocumento],
		[cantidad] AS [cantidad]
	FROM [gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumento]')) DROP VIEW [dbo].[view_gen_localizacion_itemDocumento]
GO
CREATE  VIEW [view_gen_localizacion_itemDocumento] AS
SELECT 	[gen_localizacion_itemDocumento].[id] AS [id],
		[gen_localizacion_itemDocumento].[uid] AS [uid],
		[gen_localizacion_itemDocumento].[eid] AS [eid],
		[gen_localizacion_itemDocumento].[id_usuario_modifico] AS [id_usuario_modifico],
		[gen_localizacion_itemDocumento].[id_usuario_creo] AS [id_usuario_creo],
		[gen_localizacion_itemDocumento].[fechaModificacion] AS [fechaModificacion],
		[gen_localizacion_itemDocumento].[fechaCreacion] AS [fechaCreacion],
		[gen_localizacion_itemDocumento].[active] AS [active],
		[gen_localizacion_itemDocumento].[localizacion_itemDocumento] AS [localizacion_itemDocumento],
		[gen_localizacion_itemDocumento].[id_localizacion] AS [id_localizacion],
[gen_localizacion].[localizacion] as [gen_localizacion_localizacion],
[gen_localizacion].[localizacion_codigo] as [gen_localizacion_localizacion_codigo],
[gen_localizacion].[id_catalogo_bodega] as [gen_localizacion_id_catalogo_bodega],
[gen_localizacion].[existencia] as [gen_localizacion_existencia],
[gen_localizacion].[existenciaMaxima] as [gen_localizacion_existenciaMaxima],
		[gen_localizacion_itemDocumento].[id_itemDocumento] AS [id_itemDocumento],
[doc_itemDocumento].[itemDocumento] as [doc_itemDocumento_itemDocumento],
[doc_itemDocumento].[itemDocumento_codigo] as [doc_itemDocumento_itemDocumento_codigo],
[doc_itemDocumento].[detalle] as [doc_itemDocumento_detalle],
[doc_itemDocumento].[horasOrdinales] as [doc_itemDocumento_horasOrdinales],
[doc_itemDocumento].[horasFestivas] as [doc_itemDocumento_horasFestivas],
[doc_itemDocumento].[horasNocturnas] as [doc_itemDocumento_horasNocturnas],
[doc_itemDocumento].[cantidadPlaneado] as [doc_itemDocumento_cantidadPlaneado],
[doc_itemDocumento].[cantidadEjecutado] as [doc_itemDocumento_cantidadEjecutado],
[doc_itemDocumento].[valorUnitarioPlaneado] as [doc_itemDocumento_valorUnitarioPlaneado],
[doc_itemDocumento].[valorUnitarioEjecutado] as [doc_itemDocumento_valorUnitarioEjecutado],
[doc_itemDocumento].[subtotalPlaneado] as [doc_itemDocumento_subtotalPlaneado],
[doc_itemDocumento].[subtotalEjecutado] as [doc_itemDocumento_subtotalEjecutado],
[doc_itemDocumento].[totalPlaneado] as [doc_itemDocumento_totalPlaneado],
[doc_itemDocumento].[totalEjecutado] as [doc_itemDocumento_totalEjecutado],
[doc_itemDocumento].[porciva] as [doc_itemDocumento_porciva],
[doc_itemDocumento].[ivaPlaneado] as [doc_itemDocumento_ivaPlaneado],
[doc_itemDocumento].[ivaEjecutado] as [doc_itemDocumento_ivaEjecutado],
[doc_itemDocumento].[porcdto] as [doc_itemDocumento_porcdto],
[doc_itemDocumento].[dtoPlaneado] as [doc_itemDocumento_dtoPlaneado],
[doc_itemDocumento].[dtoEjecutado] as [doc_itemDocumento_dtoEjecutado],
[doc_itemDocumento].[costear] as [doc_itemDocumento_costear],
[doc_itemDocumento].[esUrgente] as [doc_itemDocumento_esUrgente],
[doc_itemDocumento].[vencimientoGarantia_ff] as [doc_itemDocumento_vencimientoGarantia_ff],
[doc_itemDocumento].[horasGarantia] as [doc_itemDocumento_horasGarantia],
[doc_itemDocumento].[porcentajeCliente] as [doc_itemDocumento_porcentajeCliente],
[doc_itemDocumento].[porcentajeDistribuidor] as [doc_itemDocumento_porcentajeDistribuidor],
[doc_itemDocumento].[porcentajeFabricante] as [doc_itemDocumento_porcentajeFabricante],
[doc_itemDocumento].[afectoInventario] as [doc_itemDocumento_afectoInventario],
[doc_itemDocumento].[id_documento] as [doc_itemDocumento_id_documento],
[doc_itemDocumento].[id_itemDocumento] as [doc_itemDocumento_id_itemDocumento],
[doc_itemDocumento].[id_centroCosto] as [doc_itemDocumento_id_centroCosto],
[doc_itemDocumento].[id_catalogo] as [doc_itemDocumento_id_catalogo],
[doc_itemDocumento].[id_bodega] as [doc_itemDocumento_id_bodega],
[doc_itemDocumento].[id_incoterm] as [doc_itemDocumento_id_incoterm],
[doc_itemDocumento].[id_itemDocumento_superior] as [doc_itemDocumento_id_itemDocumento_superior],
[doc_itemDocumento].[costoPlaneado] as [doc_itemDocumento_costoPlaneado],
[doc_itemDocumento].[costoEjecutado] as [doc_itemDocumento_costoEjecutado],
		[gen_localizacion_itemDocumento].[cantidad] AS [cantidad],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [gen_localizacion_itemDocumento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gen_localizacion_itemDocumento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gen_localizacion_itemDocumento].[id_usuario_creo]
	INNER JOIN [gen_localizacion] ON [gen_localizacion].id=[gen_localizacion_itemDocumento].[id_localizacion]
	INNER JOIN [doc_itemDocumento] ON [doc_itemDocumento].id=[gen_localizacion_itemDocumento].[id_itemDocumento]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [gen_localizacion_itemDocumento].eid = [empresaCodigo].[codigo] and empresaCodigo.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_gen_localizacion_itemDocumentosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentosXusuario_modifico]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumentosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentosXusuario_creo]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumentosXlocalizacion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentosXlocalizacion]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentosXlocalizacion]
	@p_id_localizacion INT
AS
BEGIN
	SELECT * 
	FROM [view_gen_localizacion_itemDocumento]
	WHERE ([id_localizacion]= @p_id_localizacion)
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_gen_localizacion_itemDocumentosXitemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentosXitemDocumento]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentosXitemDocumento]
	@p_id_itemDocumento INT
AS
BEGIN
	SELECT * 
	FROM [view_gen_localizacion_itemDocumento]
	WHERE ([id_itemDocumento]= @p_id_itemDocumento)
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_gen_localizacion_itemDocumentos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentos]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentos]
	
	@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_gen_localizacion_itemDocumento]
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_gen_localizacion_itemDocumentos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gen_localizacion_itemDocumentos]
GO
CREATE PROCEDURE [lis_gen_localizacion_itemDocumentos]
	AS
BEGIN
	SELECT id AS id,
[localizacion_itemDocumento] AS [gen_localizacion_itemDocumento]
	FROM [gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_gen_localizacion_itemDocumento]
GO
CREATE PROCEDURE [upd_gen_localizacion_itemDocumento]
	@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_localizacion_itemDocumento varchar(300) = null,
		@p_id_localizacion int = null,
		@p_id_itemDocumento int = null,
		@p_cantidad int = null
AS
BEGIN
		UPDATE [gen_localizacion_itemDocumento]
		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(),
			[localizacion_itemDocumento] = isnull(@p_localizacion_itemDocumento,[localizacion_itemDocumento]),
			[id_localizacion] = isnull(@p_id_localizacion,[id_localizacion]),
			[id_itemDocumento] = isnull(@p_id_itemDocumento,[id_itemDocumento]),
			[cantidad] = isnull(@p_cantidad,[cantidad])
		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_gen_localizacion_itemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_gen_localizacion_itemDocumento]
GO
CREATE PROCEDURE [ins_gen_localizacion_itemDocumento]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_localizacion_itemDocumento varchar(300),
		@p_id_localizacion int,
		@p_id_itemDocumento int,
		@p_cantidad int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [gen_localizacion_itemDocumento]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[localizacion_itemDocumento],
			[id_localizacion],
			[id_itemDocumento],
			[cantidad])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_localizacion_itemDocumento,
			@p_id_localizacion,
			@p_id_itemDocumento,
			@p_cantidad)
		SET @v_id = scope_identity()
UPDATE [gen_localizacion_itemDocumento] 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_gen_localizacion_itemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_gen_localizacion_itemDocumento]
GO
CREATE PROCEDURE [act_gen_localizacion_itemDocumento]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gen_localizacion_itemDocumento_m]
GO
CREATE PROCEDURE [reg_gen_localizacion_itemDocumento_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],
		[localizacion_itemDocumento] AS [localizacion_itemDocumento],
		[id_localizacion] AS [id_localizacion],
		[id_itemDocumento] AS [id_itemDocumento],
		[cantidad] AS [cantidad]
	FROM [gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumentosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumentosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumentosXlocalizacion_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentosXlocalizacion_m]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentosXlocalizacion_m]
	@p_id_localizacion INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gen_localizacion_itemDocumento]
	WHERE ([id_localizacion]= @p_id_localizacion)
	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_gen_localizacion_itemDocumentosXitemDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentosXitemDocumento_m]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentosXitemDocumento_m]
	@p_id_itemDocumento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gen_localizacion_itemDocumento]
	WHERE ([id_itemDocumento]= @p_id_itemDocumento)
	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_gen_localizacion_itemDocumentos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_localizacion_itemDocumentos_m]
GO
CREATE PROCEDURE [sel_gen_localizacion_itemDocumentos_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_gen_localizacion_itemDocumento]
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_gen_localizacion_itemDocumentos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gen_localizacion_itemDocumentos_m]
GO
CREATE PROCEDURE [lis_gen_localizacion_itemDocumentos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[localizacion_itemDocumento] AS [gen_localizacion_itemDocumento]
	FROM [gen_localizacion_itemDocumento]
	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_gen_localizacion_itemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_gen_localizacion_itemDocumento]
GO
CREATE PROCEDURE [aud_gen_localizacion_itemDocumento]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [gen_localizacion_itemDocumento].id as id_tabla,
	[gen_localizacion_itemDocumento].id_usuario_modifico as id_usuario_modifico,
	[gen_localizacion_itemDocumento].id_usuario_creo as id_usuario_creo,
	[gen_localizacion_itemDocumento].fechaModificacion as fechaModificacion,
	[gen_localizacion_itemDocumento].fechaCreacion as fechaCreacion,
	[gen_localizacion_itemDocumento].active as active,
	[gen_localizacion_itemDocumento].[localizacion_itemDocumento] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [gen_localizacion_itemDocumento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gen_localizacion_itemDocumento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gen_localizacion_itemDocumento].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'gen_localizacion_itemDocumento'
-----------------------------------04/08/2016 9:09:06