
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_plantillaListaChequeo_planilla]') AND type in (N'P', N'PC'))
BEGIN
execute('

	CREATE PROCEDURE [dbo].[sel_plantillaListaChequeo_planilla] 
		@p_idCheckList int
	AS
	BEGIN
	
		SET NOCOUNT ON;
	

	   SELECT CLA.id_atributo id
	   ,CLA.cat_atributo_atributo as item
	   ,SA.seccionAtributo as seccion
	   ,SA.seccionAtributo_codigo as seccion_codigo
	   ,SA.id as idSeccion
	   ,CLA.cat_atributo_id_tipoAtributo as tipo
	   ,dbo.f_opcionesAtributo(CLA.id_atributo,1) as IDsOpciones
	   ,dbo.f_opcionesAtributo(CLA.id_atributo,0) as textosOpciones
	   ,CLA.cat_atributo_esVariable as esVariable
	   ,CLA.orden as orden
	   ,CLA.id_pruebaCheckList as id_lista
	   ,CLA.cat_atributo_esObligatorio as obligatorio
	   ,CLA.cat_atributo_valorMinimo minimo
	   ,CLA.cat_atributo_ValorMaximo maximo
	   ,UNI.unidad as unidad
	   ,CLA.pruebaCheckList_atributo as vrDefecto
	   FROM view_cat_pruebaCheckList_atributo CLA
	   INNER JOIN cat_seccionAtributo SA on SA.id=CLA.cat_atributo_id_seccionAtributo
	   INNER JOIN gen_unidad UNI on UNI.id=CLA.cat_atributo_id_unidad
	   WHERE CLA.id_pruebachecklist=@p_idCheckList and CLA.active=1
	   ORDER BY SA.orden,CLA.orden
	END
')

END