/* Fee Transfer Paid — detail (DatawarehouseNCM) Crystal: FeeTransferPaid.rpt (Pm-Detail = on) Fact: dbo.FactFeeTransferPaid BO GetFees: paid rows in date range, then CMs for those invoices. Same here: filter Paid by TrxDate, then include CM/CMHistory for those InvoiceNo. */ DECLARE @StartDate datetime = '2026-01-01'; DECLARE @EndDate datetime = '2026-01-31'; DECLARE @PaidInvoices TABLE (InvoiceNo varchar(21) PRIMARY KEY); INSERT INTO @PaidInvoices (InvoiceNo) SELECT DISTINCT InvoiceNo FROM dbo.FactFeeTransferPaid WHERE RowSource = 'Paid' AND TrxDate >= @StartDate AND TrxDate <= @EndDate; SELECT f.InvoiceNo, f.TrxDate, f.CodeId, f.ServiceCode, f.Amount, f.RowSource FROM dbo.FactFeeTransferPaid f INNER JOIN @PaidInvoices p ON p.InvoiceNo = f.InvoiceNo ORDER BY f.InvoiceNo, f.RowSource, f.CodeId, f.ServiceCode;