Hey - I haven’t forgotten about you. I’m pushing a bunch automation updates last night and today.
The description field is primarily used by payment integrations to store transaction data. There is a post by QMcKay from way back about storing manually-inputted data after a payment transaction.
I don’t think there’s an event for change payment (maybe on a new version - not sure) and having a user input the value is tedius and error-prone.
@Memo wow think I cracked it, using your same code above
long but working
DECLARE @UserName NVARCHAR(255) = N'@1';
DECLARE @StartDate NVARCHAR(25) = N'{Start}';
DECLARE @EndDate NVARCHAR(25) = N'{End}';
DECLARE @UserId INT;
SELECT @UserId = Id
FROM dbo.Users
WHERE Name = @UserName;
IF (@UserId IS NOT NULL)
BEGIN
select pp.Name, sum(pp.pamount - ISNULL(cp.pamount,0)) as payment
from (select p.UserId, p.Name, CONVERT(DECIMAL(16, 2), ROUND(SUM((p.Amount) / p.ExchangeRate), 2)) as pamount
from dbo.Payments p where p.Date between @StartDate AND @EndDate
group by p.UserId, p.Name) pp left join (
select cp.UserId, cp.Name,CONVERT(DECIMAL(16, 2), ROUND(SUM((ISNULL(cp.Amount, 0)) / cp.ExchangeRate), 2)) as pamount
from dbo.ChangePayments cp where cp.Date between @StartDate AND @EndDate
group by cp.UserId, cp.Name) cp
on pp.UserId = cp.UserId and pp.Name = cp.Name
where pp.UserId = @UserId
group by pp.UserId, pp.Name
END;
I was thinking about seeing if there was a way to grab the payment account from the payment transaction then aggregate/join on change payments. Or just mash everything into a temp table and select/sum from there. I just haven’t gotten around to it.
I don’t either. I use SQL Prompt to format the DDL/DML.