
/****** Object:  StoredProcedure [dbo].[mob_plantillaListaChequeo_sucursal]    Script Date: 7/1/2020 4:16:46 PM ******/
if exists(select 1 from sys.procedures where name='mob_plantillaListaChequeo_ot') DROP PROCEDURE [dbo].[mob_plantillaListaChequeo_ot]
GO

/****** Object:  StoredProcedure [dbo].[mob_plantillaListaChequeo_sucursal]    Script Date: 7/1/2020 4:16:46 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[mob_plantillaListaChequeo_ot] 
	@p_idOT int
AS
BEGIN
	
	SET NOCOUNT ON;

	declare @idLista int

	set @idLista=(select top 1 DT.id_pruebaCheckList
				from cat_detalleTempario DT
					inner join [cat_catalogo.tempario] TEMP on TEMP.id=DT.[id_Catalogo.tempario]
					inner join cnt_visitaFija VF on VF.[id_catalogo.tempario]=TEMP.id
				where VF.[id_documento.ot]=@p_idOT)

	SELECT CLA.id_atributo id
		,SA.seccionAtributo as seccion
		,SA.seccionAtributo_codigo as seccion_codigo
		,CLA.cat_atributo_id_seccionAtributo as id_seccionAtributo
		,CLA.id_pruebaCheckList as id_lista
		,'' as vrDefecto
		,fam.id as id_familia
		,fam.familia as familia
   FROM view_cat_pruebaCheckList_atributo CLA
	   INNER JOIN cat_seccionAtributo SA on SA.id=CLA.cat_atributo_id_seccionAtributo
	   inner join cat_pruebachecklist on CLA.id_pruebaChecklist = cat_pruebachecklist.id
		left outer join gen_familia fam on fam.familia_codigo=(select datos from dbo.split(SA.seccionatributo_codigo,'-')where pos=2) 
   WHERE CLA.id_pruebaChecklist=@idLista
   ORDER BY SA.orden,CLA.orden
   
END


GO

