• Why bother with the temp table? Why not just imbed the select into your where clause?

    SELECT

    SO.SalesPersonID, C.FirstName + ' ' + C.LastName AS SalesPerson

    , COUNT(*) AS Orders

    , SUM(SO.SubTotal) AS TotalAmount

    FROM Sales.SalesOrderHeader SO

    INNER JOIN HumanResources.Employee E ON

    SO.SalesPersonID = E.EmployeeID

    INNER JOIN Person.Contact C ON

    E.ContactID = C.ContactID

    WHERE SO.OrderDate BETWEEN @StartDate And @EndDate

    -- The dynamic IN predicate.

    AND SO.SalesPersonID IN (SELECT CONVERT(INT, Item) AS SalesPersonID

    FROM dbo.DelimitedSplit8K(@SalesPeople, ','))

    GROUP BY

    SO.SalesPersonID, C.FirstName, C.LastName