• When you run same query second time SQL Server does not actually execute it, it uses resultset stored in cache.

    Try to run

    DBCC FREEPROCCACHE

    after 1st execution and run query again.

    2nd time will be just like 1st time.

    🙂

    _____________
    Code for TallyGenerator