--Versão: EU --deleta documento e sua movimentação no estoque select * from DocumentoEstoque where Numero in (43845, 43846, 43847, 43848, 43849) delete DocumentoEstoque where Numero in (43845, 43846, 43847, 43848, 43849) select * from ItemDocumentoEstoque where Documento in (54831, 54832, 54833, 54834, 54835) select * from MovimentoAlmoxarifado where ItemDocumentoGerador in (59616, 59617, 59618, 59619, 59620) delete MovimentoAlmoxarifado where ItemDocumentoGerador in (59616, 59617, 59618, 59619, 59620) --Versão: Emerson /*Periodo: 01/02/2017 a 28/02/2017 Material:Codigo: 1 Carvao vegetal Tipo doc. Entrada: NFE Tipo Doc. Saida: SMP Tipo Doc. Devolução: NFD Almoxarifado: MA */ update DocumentoEstoque set DocumentoEstornado = null where AutoId in ( select d.AutoId from DocumentoEstoque d inner join ItemDocumentoEstoque i on i.Documento = d.AutoId inner join Material m on m.AutoId =i .MaterialDoc inner join Almoxarifado a on a.AutoId=d.AlmoxarifadoDoc where m.Codigo='1' and a.Codigo='ma' and d.DataDocumento >= '2017-02-01' and d.DocumentoEstornado is not null )