
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_doc_documentoOtProgramada]')) DROP VIEW [dbo].[view_doc_documentoOtProgramada]
GO
CREATE VIEW view_doc_documentoOtProgramada AS
select distinct OT.id
from [view_doc_documento_ot] OT
inner join view_ort_programacion PROG on PROG.[id_documento.ot]=OT.id
where PROG.id_tipoprogramacion=3 and OT.doc_documento_ot_doc_estadoTipoDocumento_estadoTipoDocumento_codigo ='PRO' 

GO
