• Oh, yep, that's part of what's confusing me currently :-P. That query's part of a stored procedure, and it uses dynamic SQL; however, @StartDate and @EndDate are input parameters for the procedure, and the dynamic SQL is parameterized using the input parameters.

    That's why the cache problem didn't even occur to me... It seems like the whole thing should've plopped right into the cache and gotten reused the whole time, but something's stopping the reuse. Didn't have much time to experiment with it yesterday, but I should have a good bit of time to tinker with it today. I'll post any interesting findings for the benefit of the readers, should I stumble upon something.

    EDIT: Just in case it's part of the problem, the dynamic SQL is basically done like so:

    DECLARE @sql nvarchar(max) =

    'SELECT (columns)

    FROM ['+column+'].dbo.(table)

    WHERE (conditions including @StartDate and @EndDate)'

    +CHAR(10)

    FROM #DatabaseList

    EXEC sp_executesql @sql,N'@StartDateValue datetime,@EndDateValue datetime',@StartDateValue = @StartDate, @EndDateValue = @EndDate

    Basically, I have a table that holds the system names and front-end names of our databases, and I'm using it to run a query against multiple databases.

    - 😀