My query is below. The crazy thing that makes it run, is if I rename the parameter @Eslam Nader to @ajax , the query works fine. What am I missing? Why would this solve the issue?
SELECT
MONTH(Received) as Month,
YEAR(Received) as Year,
SUM(dd.AmountCents) as TotalDonated,
AVG(dd.AmountCents) as AverageDonation,
COUNT(dd.DonationId) as TotalDonations,
COUNT(Distinct DonorId) as UniqueDonors,
MAX(m.Median) as MedianDonation
FROM [dbo].[Donations] d
inner join DonationDesignations dd on dd.DonationId = d.DonationId
inner join
(
Select
DonationId,
Month(Received) as Month,
Year(Received) as Year,
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY AmountCents desc) OVER (PARTITION BY YEAR(Received), MONTH(Received)) as Median
from [dbo].[Donations]
where OrganizationId = @orgId
and Status = 'succeeded'
and Received >= @START
and Received <= @Eslam Nader
and IsRefunded = 0
) m on m.DonationId = d.DonationId
where OrganizationId = @orgId and IsRefunded = 0 and Status = 'succeeded'
and Received >= @START and Received <= @Eslam Nader
group by MONTH(Received), YEAR(Received)
order by YEAR(Received), MONTH(Received)