
CREATE VIEW [dbo].[ApiDocumentsView] AS

SELECT  * from [dbo].[ApiDocumentsViewBase] d
where --Magazyn =1 --and Stan =0 
--and 
d.DefId in (8,64,42,50,9,40,65)
and not Exists ( select * from dbo.[ApiDownloadObjects] where [objectId] = d.Id and operatorId=0 and ((type=0 and Status>=2) and ((type=0 and Status>=2) and DATEDIFF(DAY,TS,CURRENT_TIMESTAMP)<1)))
and not Exists ( select * from dbo.ApiDocuments dd where  dd.ErpId = d.ErpId and dd.VendorId=0 )



