RE: Script to delete empty batches
Another one of my "batch management" scripts. Specifically deletes Sales Batches with no transactions. Also checks SOP10100 to make sure there aren't any transactions associated with the batch (for example if I moved an invoice, but forgot to run my recalculate script or checklinks).
I added an additional "batches with dashes" where clause because that is how our sales batches are created from the invoicing system, so you will need to remove that.
select *
--Delete s
from sy00500 s
where s.numoftrx = 0 -- Only zero count
and s.series = 3 -- Sales
and s.bchsourc = 'Sales Entry' -- Sales Entry
and charindex('-',s.bachnumb) > 0 -- batches with a dash
and s.bachnumb not in (select Bachnumb -- Don't have existing invoice in SOP10100
from sop10100
group by bachnumb)