

IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_doc_documentoOtSinProgramar]')) DROP VIEW [dbo].[view_doc_documentoOtSinProgramar]
GO
CREATE VIEW view_doc_documentoOtSinProgramar AS
select distinct OT.id
from [view_doc_documento_ot] OT
left outer join view_ort_programacion PROG on PROG.[id_documento.ot]=OT.id
where PROG.id is null and OT.doc_documento_ot_doc_estadoTipoDocumento_estadoTipoDocumento_codigo!='NUE' 
and  OT.doc_documento_ot_doc_estadoTipoDocumento_estadoTipoDocumento_codigo!='PRO'