SELECT TOP(@Limit)[Id], [WorkspaceId], [CapturedAtUtc], [TotalTaskCount], [SuccessfulTaskCount], [FailedTaskCount], [AverageQueueLatencySeconds], [AverageExecutionSeconds], [TotalRuntimeSeconds], [EstimatedCostUsd], [ForecastedTaskCount], [MeanAbsolutePercentageError], [CreatedAtUtc]
FROM [dbo].[AutonomousScalingSnapshots]
WHERE [WorkspaceId] = @WorkspaceId
  AND (@CapturedAfterUtc IS NULL
   OR [CapturedAtUtc] >= @CapturedAfterUtc)
  AND (@CapturedBeforeUtc IS NULL
   OR [CapturedAtUtc]
    < @CapturedBeforeUtc)
ORDER BY [CapturedAtUtc] DESC;
