
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[a_sel_doc_resumendocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[a_sel_doc_resumendocumento]
GO
create  PROCEDURE [dbo].[a_sel_doc_resumendocumento]
	@p_idDocumento as int = 0,
	@p_eid as varchar(50) = ''
AS
BEGIN
DECLARE @fechaInicial as smalldatetime
DECLARE @tiempoMedioFallas as float
--consulta 1, Tiempo medio entre fallas
DECLARE @comentarioDocumento as varchar(100)  
set @comentarioDocumento = (select top 1 comentario from ort_programacion where [id_documento.ot] = @p_idDocumento)
select  'Trabajos' as ventana,  'Cantidad de Recordatorio' as titulo,  case when @comentarioDocumento <> null or @comentarioDocumento <> '' then @comentarioDocumento else '' end as dato 
select  top 3 'Trabajos' as ventana,  'Duracion' as titulo, CONVERT(varchar(10), count(duracion))  as dato from ort_programacion where [id_documento.ot] = @p_idDocumento

DECLARE @documento as varchar(100)  
set @documento = (select top 1  prefijo + ' ' + CONVERT(varchar(10), documento_numero) as dato from doc_documento  where  id  = @p_idDocumento)

select  'Documentos' as ventana, 'Documento' as titulo,  case when @documento <> null or @documento <> ''  then @documento else '' end as dato 

DECLARE @comentario as varchar(100)  
set @comentario = (select top 1 comentario from doc_documentoComentario where id_documento =  @p_idDocumento)
select  'Comentario' as ventana, 'Comentario' as titulo,  case when @comentario <> null or @comentario <> '' then @comentario else '' end as dato 

END

go
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[a_sel_doc_resumendocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[a_sel_doc_resumendocumento_m]
GO
create  PROCEDURE [dbo].[a_sel_doc_resumendocumento_m]
	@p_idDocumento as int = 0,
	@p_eid as varchar(50) = ''
AS
BEGIN
DECLARE @fechaInicial as smalldatetime
DECLARE @tiempoMedioFallas as float
--consulta 1, Tiempo medio entre fallas
DECLARE @comentarioDocumento as varchar(100)  
set @comentarioDocumento = (select top 1 comentario from ort_programacion where [id_documento.ot] = @p_idDocumento)
select  'Trabajos' as ventana,  'Cantidad de Recordatorio' as titulo,  case when @comentarioDocumento <> null or @comentarioDocumento <> '' then @comentarioDocumento else '' end as dato 
select  top 3 'Trabajos' as ventana,  'Duracion' as titulo, CONVERT(varchar(10), count(duracion))  as dato from ort_programacion where [id_documento.ot] = @p_idDocumento

DECLARE @documento as varchar(100)  
set @documento = (select top 1  prefijo + ' ' + CONVERT(varchar(10), documento_numero) as dato from doc_documento  where  id  = @p_idDocumento)

select  'Documentos' as ventana, 'Documento' as titulo,  case when @documento <> null or @documento <> ''  then @documento else '' end as dato 

DECLARE @comentario as varchar(100)  
set @comentario = (select top 1 comentario from doc_documentoComentario where id_documento =  @p_idDocumento)
select  'Comentario' as ventana, 'Comentario' as titulo,  case when @comentario <> null or @comentario <> '' then @comentario else '' end as dato 

END
