# Payment History and Totals

**URL:** https://forum.innovativeusers.org/t/payment-history-and-totals/1226
**Category:** Polaris Repository
**Tags:** cp-migration, polaris-pat-account
**Created:** [June 2, 2023, 9:02pm UTC](https://forum.innovativeusers.org/t/payment-history-and-totals/1226 "2023-06-02T21:02:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://forum.innovativeusers.org/uploads/db7787/original/2X/8/8519ee8eef6492f310ea87d4ce482d931f01eef2.png) [@system](https://forum.innovativeusers.org/u/system)
#### Post date: [June 2, 2023, 9:02pm UTC](https://forum.innovativeusers.org/t/payment-history-and-totals/1226/1 "2023-06-02T21:02:58Z")

</div>

# Payment History and Totals

This pulls total payment history, by fee reason, for libraries within a system. Because it’s pulling from the Transactions database, it’s a query that will get you historical information.

```SQL
SELECT
    torg.Name AS "Branch/Library",
    frc.FeeDescription AS "Fee Reason",
    COUNT(DISTINCT th.TransactionID) AS "Number of Transactions", 
    STR(ROUND(CAST(SUM(mon.numvalue/1000.00) AS MONEY),2),20,2) AS "Amount"

FROM
    PolarisTransactions.Polaris.TransactionHeaders th WITH (NOLOCK) 

INNER JOIN
    PolarisTransactions.Polaris.TransactionDetails td WITH (NOLOCK) ON (th.TransactionID = td.TransactionID) 
INNER JOIN
    PolarisTransactions.Polaris.TransactionDetails mon WITH (NOLOCK) ON (th.TransactionID = mon.TransactionID AND mon.TransactionSubTypeID = 141)  
INNER JOIN
    Polaris.Polaris.Organizations torg WITH (NOLOCK) ON (th.OrganizationID = torg.OrganizationID)  
LEFT JOIN
    Polaris.Polaris.FeeReasonCodes frc WITH (NOLOCK) ON (td.numValue = frc.FeeReasonCodeID)

WHERE
    th.TransactionTypeID = 6016 -- Patron accounting payment
AND
    td.TransactionSubTypeID = 8 -- FeeReasonCodeID
AND
    th.TranClientDate BETWEEN '2021-01-01 00:00:00.000' AND '2021-02-22 23:59:59.999' -- Adjust dates as you like
AND
    th.OrganizationID IN (1,2,3,4,5,6,7,8,9,10)  

GROUP BY
    torg.name,
    frc.FeeDescription
ORDER BY
    torg.name,
    frc.FeeDescription

```
