declare
@clientID int= 20235,
@billingStartDate DATETIME= CONVERT(DATE,'1/6/2020'),
@billingEndDate DATETIME= CONVERT(DATE,'2/6/2020')
SELECT c.clientname,
c.groupNumber,
ec.clientID,
ec.vendorFieldLV,
ec.enrolledCount,
ec.effectiveDate,
ec.terminationDate,
ec.savedUserID,
ua.firstname,
ua.lastname,
ec.savedDateTime,
ec.removedDate,
c.democlient,
c.inactivedate,
c.terminationDate
FROM enrollmentCountsByVendor ec with (NOLOCK)
INNER JOIN client c with (NOLOCK) ON c.clientid = ec.clientid
INNER JOIN clientTree ct with (NOLOCK) ON c.clientID = ct.clientid AND ct.alphaClientID = @clientID
INNER JOIN useraccount ua with (NOLOCK) ON ec.savedUserID = ua.userID
WHERE ec.savedDateTime BETWEEN @billingStartDate AND @billingEndDate
ORDER BY c.clientName, ec.effectiveDate