IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[_asb_atributosOtCall]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[_asb_atributosOtCall]
go
CREATE PROCEDURE [dbo].[_asb_atributosOtCall] 
@p_idEquipo int,
@p_codOpcionAtributo varchar(100)

AS
BEGIN

	if @p_codOpcionAtributo = '0'
	begin
		declare @modelo as int=(Select [id_catalogo.equipo] from equ_equipo where id=@p_idEquipo)

		--IF @modelo=13
		--BEGIN
		--Select null
		--END

		--ELSE IF @modelo <>13
		--BEGIN
		Select
		ATR.id_atributo as idAtributo
		,ATR.id_subtipoDocumento idSubtipoDoc
		,case when (select count(id) from view_equ_opcionAtributoDependiente where id_opcionAtributoPadre = 0) = 0 then dbo.f_opcionesAtributo(ATR.id_atributo,2) else '' end as opcionesCod 
		,case when (select count(id) from view_equ_opcionAtributoDependiente where id_opcionAtributoPadre = 0) = 0 then dbo.f_opcionesAtributo(ATR.id_atributo,0) else '' end as opcionesTexto
		,ATR.doc_subtipoDocumento_subtipoDocumento_codigo as subtipoDoc_codigo
		,ATR.cat_atributo_atributo atributo,cat_atributo_atributo_codigo as atributoCod
		,ATR.cat_atributo_id_tipoAtributo as idTipoAtributo
		,ATR.cat_atributo_esObligatorio as esObligatorio
		,ATR.orden as orden
		from
		view_doc_subtipoDocumento_atributo ATR
		where
		ATR.id_subtipoDocumento=2
		and ATR.cat_atributo_id_seccionAtributo=183
and ATR.cat_atributo_id_tipoAtributo=9
		--END
	end
	else
	begin
		Select
			ATR.id_atributo as idAtributo
			,ATR.id_subtipoDocumento idSubtipoDoc
			,case when (select count(id) from view_equ_opcionAtributoDependiente where id_opcionAtributoPadre = 0) = 0 then dbo.f_opcionesAtributo(ATR.id_atributo,2) else '' end as opcionesCod 
			,case when (select count(id) from view_equ_opcionAtributoDependiente where id_opcionAtributoPadre = 0) = 0 then dbo.f_opcionesAtributo(ATR.id_atributo,0) else '' end as opcionesTexto
			,ATR.doc_subtipoDocumento_subtipoDocumento_codigo as subtipoDoc_codigo
			,ATR.cat_atributo_atributo atributo,cat_atributo_atributo_codigo as atributoCod
			,ATR.cat_atributo_id_tipoAtributo as idTipoAtributo
			,ATR.cat_atributo_esObligatorio as esObligatorio
			,ATR.orden as orden
		from
			view_doc_subtipoDocumento_atributo ATR
		where
			ATR.id_subtipoDocumento=2 and
			ATR.id_atributo in (select id_atributo from view_cat_atributo_opcionAtributo where equ_opcionAtributo_opcionAtributo_codigo = @p_codOpcionAtributo)
	end

END