Browse Source

#25998 low txn report

master
Leeza Baidar 7 months ago
parent
commit
2cbbea8f4c
  1. 74
      Deployment/25998-LowTxnReport/proc_low_txn_report.sql

74
Deployment/25998-LowTxnReport/proc_low_txn_report.sql

@ -0,0 +1,74 @@
ALTER PROCEDURE [dbo].[proc_low_txn_report] @FLAG VARCHAR(20)
,@user VARCHAR(30)
,@fromDate VARCHAR(10) = NULL
AS
SET NOCOUNT ON;
IF @FLAG = 'txn-report'
BEGIN
WITH CustomerDetails
AS (
SELECT customerId
,membershipId
,(ISNULL(firstName, '') + ' ' + ISNULL(middleName, '') + ' ' + ISNULL(lastName1, '')) AS fullName
,email
,mobile
,zipCode
,address + ', ' + ISNULL(city, '') AS Address1
,createdDate
FROM customerMaster
WHERE createdDate BETWEEN '2023-11-01'
AND GETDATE()
)
,TransactionCounts
AS (
SELECT cm.customerId
,ISNULL(COUNT(ts.tranId), 0) AS txnCount
,MAX(rt.createdDate) AS lastTxnDate
FROM CustomerDetails cm
LEFT JOIN vwTranSenders ts ON cm.customerId = ts.customerId
LEFT JOIN vwRemitTran rt ON ISNULL(rt.id, rt.holdTranId) = ts.tranId
GROUP BY cm.customerId
)
,TranDetails
AS (
SELECT cd.customerId AS customerId
,cd.membershipId
,cd.Address1
,cd.fullName
,cd.email
,cd.mobile
,cd.zipCode
,cd.createdDate
,ISNULL(tc.txnCount, 0) AS txnCount
,tc.lastTxnDate
FROM CustomerDetails cd
LEFT JOIN TransactionCounts tc ON cd.customerId = tc.customerId
)
SELECT ROW_NUMBER() OVER (
ORDER BY txnCount DESC
) AS SN
--,customerId
,membershipId
,fullName
,email
,mobile
,zipCode
,Address1
,createdDate
,txnCount
,lastTxnDate
FROM TranDetails
WHERE lastTxnDate <= CONVERT(DATE, @fromDate)
OR lastTxnDate IS NULL
ORDER BY txnCount DESC
EXEC proc_errorHandler '0'
,'Report has been prepared successfully.'
,NULL
SELECT 'From Date' head
,@fromDate VALUE
SELECT 'Low Txn report' title
END
Loading…
Cancel
Save