Quantcast
Channel: Microsoft Dynamics RMS Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4469

RE: SQL Query to delete all the transactions older than year 2016

$
0
0

Please make sure you backup first!

Here is a script that you can run based on the batch numbers. Be aware this deletes the data used by reports also, so no sales data will show up prior to 2016, or whatever batch number you set SELECT @BatchNumberKeep = 12028 to. Also make sure to change the last part, YOURDATABASENAME, to the correct name

DECLARE @BatchNumberKeep int

SELECT @BatchNumberKeep = 12028

DELETE Shipping FROM [Transaction]
     WHERE BatchNumber < @BatchNumberKeep AND Shipping.TransactionNumber =

[Transaction].TransactionNumber

--DELETE TransactionEntry FROM [Transaction]
--     WHERE BatchNumber < @BatchNumberKeep AND

--TransactionEntry.TransactionNumber = [Transaction].TransactionNumber

DELETE TaxEntry FROM [Transaction]
     WHERE BatchNumber < @BatchNumberKeep AND TaxEntry.TransactionNumber =

[Transaction].TransactionNumber

DELETE SignatureCapture FROM TenderEntry
     WHERE BatchNumber < @BatchNumberKeep AND

SignatureCapture.TenderEntryID = TenderEntry.ID

DELETE [Transaction] WHERE BatchNumber < @BatchNumberKeep

DELETE Journal WHERE BatchNumber < @BatchNumberKeep

DELETE TaxTotals WHERE BatchNumber < @BatchNumberKeep

DELETE TenderEntry WHERE BatchNumber < @BatchNumberKeep

DELETE TenderTotals WHERE BatchNumber < @BatchNumberKeep

DELETE Batch WHERE BatchNumber < @BatchNumberKeep
--DBCC SHRINKDATABASE (YOURDATABASENAME)

This process will take awhile depending on the data you have. You should do it when the store is not open. Also, BACKUP!!!. :P

And I always delete small range sets of batches, instead of all at once


Viewing all articles
Browse latest Browse all 4469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>