IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_ort_reporteTecnico_falla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_ort_reporteTecnico_falla]
GO
CREATE PROCEDURE [reg_ort_reporteTecnico_falla]
	@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],
		[reporteTecnico_falla] AS [reporteTecnico_falla],
		[id_reporteTecnico] AS [id_reporteTecnico],
		[id_falla] AS [id_falla],
		[id_falla_causa] AS [id_falla_causa],
		[id_falla_efecto] AS [id_falla_efecto]
	FROM [ort_reporteTecnico_falla]
	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_ort_reporteTecnico_falla]')) DROP VIEW [dbo].[view_ort_reporteTecnico_falla]
GO
CREATE  VIEW [view_ort_reporteTecnico_falla] AS
SELECT 	[ort_reporteTecnico_falla].[id] AS [id],
		[ort_reporteTecnico_falla].[uid] AS [uid],
		[ort_reporteTecnico_falla].[eid] AS [eid],
		[ort_reporteTecnico_falla].[id_usuario_modifico] AS [id_usuario_modifico],
		[ort_reporteTecnico_falla].[id_usuario_creo] AS [id_usuario_creo],
		[ort_reporteTecnico_falla].[fechaModificacion] AS [fechaModificacion],
		[ort_reporteTecnico_falla].[fechaCreacion] AS [fechaCreacion],
		[ort_reporteTecnico_falla].[active] AS [active],
		[ort_reporteTecnico_falla].[reporteTecnico_falla] AS [reporteTecnico_falla],
		[ort_reporteTecnico_falla].[id_reporteTecnico] AS [id_reporteTecnico],
[ort_reporteTecnico].[reporteTecnico] as [ort_reporteTecnico_reporteTecnico],
[ort_reporteTecnico].[reporteTecnico_codigo] as [ort_reporteTecnico_reporteTecnico_codigo],
[ort_reporteTecnico].[numero] as [ort_reporteTecnico_numero],
[ort_reporteTecnico].[trabajos] as [ort_reporteTecnico_trabajos],
[ort_reporteTecnico].[recomendaciones] as [ort_reporteTecnico_recomendaciones],
[ort_reporteTecnico].[compromisos] as [ort_reporteTecnico_compromisos],
[ort_reporteTecnico].[id_gasto] as [ort_reporteTecnico_id_gasto],
[ort_reporteTecnico].[id_canalAtencion] as [ort_reporteTecnico_id_canalAtencion],
		[ort_reporteTecnico_falla].[id_falla] AS [id_falla],
[equ_falla].[falla] as [equ_falla_falla],
[equ_falla].[falla_codigo] as [equ_falla_falla_codigo],
[equ_falla].[procedimiento] as [equ_falla_procedimiento],
[equ_falla].[id_tipoFalla] as [equ_falla_id_tipoFalla],
[equ_falla].[id_falla] as [equ_falla_id_falla],
		[ort_reporteTecnico_falla].[id_falla_causa] AS [id_falla_causa],
[equ_falla_causa].[falla] as [equ_falla_causa_falla],
[equ_falla_causa].[falla_codigo] as [equ_falla_causa_falla_codigo],
[equ_falla_causa].[procedimiento] as [equ_falla_causa_procedimiento],
[equ_falla_causa].[id_tipoFalla] as [equ_falla_causa_id_tipoFalla],
[equ_falla_causa].[id_falla] as [equ_falla_causa_id_falla],
		[ort_reporteTecnico_falla].[id_falla_efecto] AS [id_falla_efecto],
[equ_falla_efecto].[falla] as [equ_falla_efecto_falla],
[equ_falla_efecto].[falla_codigo] as [equ_falla_efecto_falla_codigo],
[equ_falla_efecto].[procedimiento] as [equ_falla_efecto_procedimiento],
[equ_falla_efecto].[id_tipoFalla] as [equ_falla_efecto_id_tipoFalla],
[equ_falla_efecto].[id_falla] as [equ_falla_efecto_id_falla],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [ort_reporteTecnico_falla]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[ort_reporteTecnico_falla].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[ort_reporteTecnico_falla].[id_usuario_creo]
	INNER JOIN [ort_reporteTecnico] ON [ort_reporteTecnico].id=[ort_reporteTecnico_falla].[id_reporteTecnico]
	INNER JOIN [equ_falla] ON [equ_falla].id=[ort_reporteTecnico_falla].[id_falla]
	INNER JOIN [equ_falla] AS [equ_falla_causa] ON [equ_falla_causa].id=[ort_reporteTecnico_falla].[id_falla_causa]
	INNER JOIN [equ_falla] AS [equ_falla_efecto] ON [equ_falla_efecto].id=[ort_reporteTecnico_falla].[id_falla_efecto]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [ort_reporteTecnico_falla].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_ort_reporteTecnico_fallasXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXusuario_modifico]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_ort_reporteTecnico_falla]
	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_ort_reporteTecnico_fallasXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXusuario_creo]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_ort_reporteTecnico_falla]
	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_ort_reporteTecnico_fallasXreporteTecnico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXreporteTecnico]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXreporteTecnico]
	@p_id_reporteTecnico INT
AS
BEGIN
	SELECT * 
	FROM [view_ort_reporteTecnico_falla]
	WHERE ([id_reporteTecnico]= @p_id_reporteTecnico)
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_ort_reporteTecnico_fallasXfalla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXfalla]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXfalla]
	@p_id_falla INT
AS
BEGIN
	SELECT * 
	FROM [view_ort_reporteTecnico_falla]
	WHERE ([id_falla]= @p_id_falla)
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_ort_reporteTecnico_fallasXfalla_causa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXfalla_causa]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXfalla_causa]
	@p_id_falla_causa INT
AS
BEGIN
	SELECT * 
	FROM [view_ort_reporteTecnico_falla]
	WHERE ([id_falla_causa]= @p_id_falla_causa)
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_ort_reporteTecnico_fallasXfalla_efecto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXfalla_efecto]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXfalla_efecto]
	@p_id_falla_efecto INT
AS
BEGIN
	SELECT * 
	FROM [view_ort_reporteTecnico_falla]
	WHERE ([id_falla_efecto]= @p_id_falla_efecto)
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_ort_reporteTecnico_fallas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallas]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallas]
	
	@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_ort_reporteTecnico_falla]
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_ort_reporteTecnico_fallas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_ort_reporteTecnico_fallas]
GO
CREATE PROCEDURE [lis_ort_reporteTecnico_fallas]
	AS
BEGIN
	SELECT id AS id,
[reporteTecnico_falla] AS [ort_reporteTecnico_falla]
	FROM [ort_reporteTecnico_falla]
	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_ort_reporteTecnico_falla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_ort_reporteTecnico_falla]
GO
CREATE PROCEDURE [upd_ort_reporteTecnico_falla]
	@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_reporteTecnico_falla varchar(300) = null,
		@p_id_reporteTecnico int = null,
		@p_id_falla int = null,
		@p_id_falla_causa int = null,
		@p_id_falla_efecto int = null
AS
BEGIN
		UPDATE [ort_reporteTecnico_falla]
		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(),
			[reporteTecnico_falla] = isnull(@p_reporteTecnico_falla,[reporteTecnico_falla]),
			[id_reporteTecnico] = isnull(@p_id_reporteTecnico,[id_reporteTecnico]),
			[id_falla] = isnull(@p_id_falla,[id_falla]),
			[id_falla_causa] = isnull(@p_id_falla_causa,[id_falla_causa]),
			[id_falla_efecto] = isnull(@p_id_falla_efecto,[id_falla_efecto])
		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_ort_reporteTecnico_falla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_ort_reporteTecnico_falla]
GO
CREATE PROCEDURE [ins_ort_reporteTecnico_falla]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_reporteTecnico_falla varchar(300),
		@p_id_reporteTecnico int,
		@p_id_falla int,
		@p_id_falla_causa int,
		@p_id_falla_efecto int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [ort_reporteTecnico_falla]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[reporteTecnico_falla],
			[id_reporteTecnico],
			[id_falla],
			[id_falla_causa],
			[id_falla_efecto])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_reporteTecnico_falla,
			@p_id_reporteTecnico,
			@p_id_falla,
			@p_id_falla_causa,
			@p_id_falla_efecto)
		SET @v_id = scope_identity()
UPDATE [ort_reporteTecnico_falla] 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_ort_reporteTecnico_falla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_ort_reporteTecnico_falla]
GO
CREATE PROCEDURE [act_ort_reporteTecnico_falla]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [ort_reporteTecnico_falla]
	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_ort_reporteTecnico_falla_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_ort_reporteTecnico_falla_m]
GO
CREATE PROCEDURE [reg_ort_reporteTecnico_falla_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],
		[reporteTecnico_falla] AS [reporteTecnico_falla],
		[id_reporteTecnico] AS [id_reporteTecnico],
		[id_falla] AS [id_falla],
		[id_falla_causa] AS [id_falla_causa],
		[id_falla_efecto] AS [id_falla_efecto]
	FROM [ort_reporteTecnico_falla]
	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_ort_reporteTecnico_fallasXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_ort_reporteTecnico_falla]
	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_ort_reporteTecnico_fallasXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXusuario_creo_m]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_ort_reporteTecnico_falla]
	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_ort_reporteTecnico_fallasXreporteTecnico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXreporteTecnico_m]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXreporteTecnico_m]
	@p_id_reporteTecnico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_ort_reporteTecnico_falla]
	WHERE ([id_reporteTecnico]= @p_id_reporteTecnico)
	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_ort_reporteTecnico_fallasXfalla_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXfalla_m]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXfalla_m]
	@p_id_falla INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_ort_reporteTecnico_falla]
	WHERE ([id_falla]= @p_id_falla)
	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_ort_reporteTecnico_fallasXfalla_causa_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXfalla_causa_m]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXfalla_causa_m]
	@p_id_falla_causa INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_ort_reporteTecnico_falla]
	WHERE ([id_falla_causa]= @p_id_falla_causa)
	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_ort_reporteTecnico_fallasXfalla_efecto_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallasXfalla_efecto_m]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallasXfalla_efecto_m]
	@p_id_falla_efecto INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_ort_reporteTecnico_falla]
	WHERE ([id_falla_efecto]= @p_id_falla_efecto)
	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_ort_reporteTecnico_fallas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_ort_reporteTecnico_fallas_m]
GO
CREATE PROCEDURE [sel_ort_reporteTecnico_fallas_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_ort_reporteTecnico_falla]
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_ort_reporteTecnico_fallas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_ort_reporteTecnico_fallas_m]
GO
CREATE PROCEDURE [lis_ort_reporteTecnico_fallas_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[reporteTecnico_falla] AS [ort_reporteTecnico_falla]
	FROM [ort_reporteTecnico_falla]
	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_ort_reporteTecnico_falla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_ort_reporteTecnico_falla]
GO
CREATE PROCEDURE [aud_ort_reporteTecnico_falla]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [ort_reporteTecnico_falla].id as id_tabla,
	[ort_reporteTecnico_falla].id_usuario_modifico as id_usuario_modifico,
	[ort_reporteTecnico_falla].id_usuario_creo as id_usuario_creo,
	[ort_reporteTecnico_falla].fechaModificacion as fechaModificacion,
	[ort_reporteTecnico_falla].fechaCreacion as fechaCreacion,
	[ort_reporteTecnico_falla].active as active,
	[ort_reporteTecnico_falla].[reporteTecnico_falla] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

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