# Weekly Dynamic: Run A/R Aging from SQL

- URL: https://dynamicaccounting.net/weekly-dynamic-run-ar-aging-from-sql/
- Date: 2010-06-07
- Topics: Tips & Hidden Features, Payables & Receivables, SQL & Data
- Type: original article

Running A/R aging can take a while. In previous tips we’ve seen that cleaning up paid transactions via Paid Transaction Removal can help speed this up . Well, this week we look at how to run A/R aging from SQL, skipping the interface all together.  
Running this script in SQL server will perform an A/R aging through the current date. Changing the @I\_dAgingDate  variable changes the date the aging runs through.  
SET NOCOUNT ON   
DECLARE @O\_iErrorState int, @I\_dAgingDate datetime   
  SELECT @I\_dAgingDate = convert(varchar(10), GetDate(), 102)   
EXEC dbo.rmAgeCustomer 0, ”, ‘þþþþþþþþþþþþþþþ’, @I\_dAgingDate, 127, 0, 0, ”, @O\_iErrorState OUT   
–SELECT @O\_iErrorState   
SET NOCOUNT OFF

[DynamicAccounting.net](/) fan Mark Wiley was kind enough to supply this Weekly Dynamic and let me share it with the you.

Update: I missed that Michael Johnson [posted this in April of 2009](http://mbsguru.blogspot.com/2009/04/automatic-aging-for-gp.html) so he get the credit too. Sorry about that Michael.
