IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_equ_analisisFalla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_equ_analisisFalla]
GO
CREATE PROCEDURE [reg_equ_analisisFalla]
	@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],
		[analisisFalla] AS [analisisFalla],
		[analisisFalla_codigo] AS [analisisFalla_codigo],
		[id_catalogo.equipo] AS [id_catalogo.equipo],
		[id_falla] AS [id_falla],
		[id_falla_causa] AS [id_falla_causa],
		[id_falla_efecto] AS [id_falla_efecto],
		[id_falla_solucion] AS [id_falla_solucion]
	FROM [equ_analisisFalla]
	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_equ_analisisFalla]')) DROP VIEW [dbo].[view_equ_analisisFalla]
GO
CREATE  VIEW [view_equ_analisisFalla] AS
SELECT 	[equ_analisisFalla].[id] AS [id],
		[equ_analisisFalla].[uid] AS [uid],
		[equ_analisisFalla].[eid] AS [eid],
		[equ_analisisFalla].[id_usuario_modifico] AS [id_usuario_modifico],
		[equ_analisisFalla].[id_usuario_creo] AS [id_usuario_creo],
		[equ_analisisFalla].[fechaModificacion] AS [fechaModificacion],
		[equ_analisisFalla].[fechaCreacion] AS [fechaCreacion],
		[equ_analisisFalla].[active] AS [active],
		[equ_analisisFalla].[analisisFalla] AS [analisisFalla],
		[equ_analisisFalla].[analisisFalla_codigo] AS [analisisFalla_codigo],
		[equ_analisisFalla].[id_catalogo.equipo] AS [id_catalogo.equipo],
[cat_catalogo.equipo].[catalogo.equipo] as [cat_catalogo.equipo_catalogo.equipo],
[cat_catalogo.equipo].[garantiaMeses] as [cat_catalogo.equipo_garantiaMeses],
[cat_catalogo.equipo].[garantiaHoras] as [cat_catalogo.equipo_garantiaHoras],
[cat_catalogo.equipo].[manejaHorometro] as [cat_catalogo.equipo_manejaHorometro],
[cat_catalogo.equipo].[id_marca] as [cat_catalogo.equipo_id_marca],
		[cat_catalogo_equipo].[catalogo_codigo] AS [cat_catalogo_equipo_catalogo_codigo],
		[cat_catalogo_equipo].[codigoInventario] AS [cat_catalogo_equipo_codigoInventario],
		[cat_catalogo_equipo].[precioVenta] AS [cat_catalogo_equipo_precioVenta],
		[cat_catalogo_equipo].[tiempoConsecucion] AS [cat_catalogo_equipo_tiempoConsecucion],
		[cat_catalogo_equipo].[esNacional] AS [cat_catalogo_equipo_esNacional],
		[cat_catalogo_equipo].[id_familia] AS [cat_catalogo_equipo_id_familia],
		[cat_catalogo_equipo].[id_subtipoCatalogo] AS [cat_catalogo_equipo_id_subtipoCatalogo],
		[cat_catalogo_equipo].[id_unidad] AS [cat_catalogo_equipo_id_unidad],
		[cat_catalogo_equipo].[id_impuesto] AS [cat_catalogo_equipo_id_impuesto],
		[cat_catalogo_equipo].[descripcion] AS [cat_catalogo_equipo_descripcion],
		[cat_catalogo_equipo].[bloquearCostear] AS [cat_catalogo_equipo_bloquearCostear],
		[equ_analisisFalla].[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],
		[equ_analisisFalla].[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],
		[equ_analisisFalla].[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],
		[equ_analisisFalla].[id_falla_solucion] AS [id_falla_solucion],
[equ_falla_solucion].[falla] as [equ_falla_solucion_falla],
[equ_falla_solucion].[falla_codigo] as [equ_falla_solucion_falla_codigo],
[equ_falla_solucion].[procedimiento] as [equ_falla_solucion_procedimiento],
[equ_falla_solucion].[id_tipoFalla] as [equ_falla_solucion_id_tipoFalla],
[equ_falla_solucion].[id_falla] as [equ_falla_solucion_id_falla],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [equ_analisisFalla]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[equ_analisisFalla].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[equ_analisisFalla].[id_usuario_creo]
	INNER JOIN [cat_catalogo.equipo] ON [cat_catalogo.equipo].id=[equ_analisisFalla].[id_catalogo.equipo]
	INNER JOIN [cat_catalogo] aS [cat_catalogo_equipo] ON [cat_catalogo.equipo].id = [cat_catalogo_equipo].id
	INNER JOIN [equ_falla] ON [equ_falla].id=[equ_analisisFalla].[id_falla]
	INNER JOIN [equ_falla] AS [equ_falla_causa] ON [equ_falla_causa].id=[equ_analisisFalla].[id_falla_causa]
	INNER JOIN [equ_falla] AS [equ_falla_efecto] ON [equ_falla_efecto].id=[equ_analisisFalla].[id_falla_efecto]
	INNER JOIN [equ_falla] AS [equ_falla_solucion] ON [equ_falla_solucion].id=[equ_analisisFalla].[id_falla_solucion]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [equ_analisisFalla].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [equ_analisisFalla].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_equ_analisisFallasXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXusuario_modifico]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXusuario_creo]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXcatalogo_equipo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXcatalogo_equipo]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXcatalogo_equipo]
	@p_id_catalogo_equipo INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_analisisFalla]
	WHERE ([id_catalogo.equipo]= @p_id_catalogo_equipo)
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_equ_analisisFallasXfalla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXfalla]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXfalla]
	@p_id_falla INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXfalla_causa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXfalla_causa]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXfalla_causa]
	@p_id_falla_causa INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXfalla_efecto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXfalla_efecto]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXfalla_efecto]
	@p_id_falla_efecto INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXfalla_solucion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXfalla_solucion]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXfalla_solucion]
	@p_id_falla_solucion INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_analisisFalla]
	WHERE ([id_falla_solucion]= @p_id_falla_solucion)
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_equ_analisisFallas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallas]
GO
CREATE PROCEDURE [sel_equ_analisisFallas]
	
	@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_equ_analisisFalla]
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_equ_analisisFallas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_equ_analisisFallas]
GO
CREATE PROCEDURE [lis_equ_analisisFallas]
	AS
BEGIN
	SELECT id AS id,
[analisisFalla] AS [equ_analisisFalla]
	FROM [equ_analisisFalla]
	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_equ_analisisFalla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_equ_analisisFalla]
GO
CREATE PROCEDURE [upd_equ_analisisFalla]
	@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_analisisFalla varchar(300) = null,
		@p_analisisFalla_codigo varchar(100) = null,
		@p_id_catalogo_equipo int = null,
		@p_id_falla int = null,
		@p_id_falla_causa int = null,
		@p_id_falla_efecto int = null,
		@p_id_falla_solucion int = null
AS
BEGIN
		UPDATE [equ_analisisFalla]
		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(),
			[analisisFalla] = isnull(@p_analisisFalla,[analisisFalla]),
			[analisisFalla_codigo] = isnull(@p_analisisFalla_codigo,[analisisFalla_codigo]),
			[id_catalogo.equipo] = isnull(@p_id_catalogo_equipo,[id_catalogo.equipo]),
			[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]),
			[id_falla_solucion] = isnull(@p_id_falla_solucion,[id_falla_solucion])
		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_equ_analisisFalla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_equ_analisisFalla]
GO
CREATE PROCEDURE [ins_equ_analisisFalla]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_analisisFalla varchar(300),
		@p_analisisFalla_codigo varchar(100),
		@p_id_catalogo_equipo int,
		@p_id_falla int,
		@p_id_falla_causa int,
		@p_id_falla_efecto int,
		@p_id_falla_solucion int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [equ_analisisFalla]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[analisisFalla],
			[analisisFalla_codigo],
			[id_catalogo.equipo],
			[id_falla],
			[id_falla_causa],
			[id_falla_efecto],
			[id_falla_solucion])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_analisisFalla,
			@p_analisisFalla_codigo,
			@p_id_catalogo_equipo,
			@p_id_falla,
			@p_id_falla_causa,
			@p_id_falla_efecto,
			@p_id_falla_solucion)
		SET @v_id = scope_identity()
UPDATE [equ_analisisFalla] 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_equ_analisisFalla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_equ_analisisFalla]
GO
CREATE PROCEDURE [act_equ_analisisFalla]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [equ_analisisFalla]
	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_equ_analisisFalla_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_equ_analisisFalla_m]
GO
CREATE PROCEDURE [reg_equ_analisisFalla_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],
		[analisisFalla] AS [analisisFalla],
		[analisisFalla_codigo] AS [analisisFalla_codigo],
		[id_catalogo.equipo] AS [id_catalogo.equipo],
		[id_falla] AS [id_falla],
		[id_falla_causa] AS [id_falla_causa],
		[id_falla_efecto] AS [id_falla_efecto],
		[id_falla_solucion] AS [id_falla_solucion]
	FROM [equ_analisisFalla]
	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_equ_analisisFallasXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXusuario_creo_m]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXcatalogo_equipo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXcatalogo_equipo_m]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXcatalogo_equipo_m]
	@p_id_catalogo_equipo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_analisisFalla]
	WHERE ([id_catalogo.equipo]= @p_id_catalogo_equipo)
	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_equ_analisisFallasXfalla_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXfalla_m]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXfalla_m]
	@p_id_falla INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXfalla_causa_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXfalla_causa_m]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXfalla_causa_m]
	@p_id_falla_causa INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXfalla_efecto_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXfalla_efecto_m]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXfalla_efecto_m]
	@p_id_falla_efecto INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_analisisFalla]
	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_equ_analisisFallasXfalla_solucion_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallasXfalla_solucion_m]
GO
CREATE PROCEDURE [sel_equ_analisisFallasXfalla_solucion_m]
	@p_id_falla_solucion INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_analisisFalla]
	WHERE ([id_falla_solucion]= @p_id_falla_solucion)
	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_equ_analisisFallas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_analisisFallas_m]
GO
CREATE PROCEDURE [sel_equ_analisisFallas_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_equ_analisisFalla]
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_equ_analisisFallas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_equ_analisisFallas_m]
GO
CREATE PROCEDURE [lis_equ_analisisFallas_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[analisisFalla] AS [equ_analisisFalla]
	FROM [equ_analisisFalla]
	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_equ_analisisFalla]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_equ_analisisFalla]
GO
CREATE PROCEDURE [aud_equ_analisisFalla]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [equ_analisisFalla].id as id_tabla,
	[equ_analisisFalla].id_usuario_modifico as id_usuario_modifico,
	[equ_analisisFalla].id_usuario_creo as id_usuario_creo,
	[equ_analisisFalla].fechaModificacion as fechaModificacion,
	[equ_analisisFalla].fechaCreacion as fechaCreacion,
	[equ_analisisFalla].active as active,
	[equ_analisisFalla].[analisisFalla] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

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