When creating lengthy T-SQL queries, sometimes a set-based approach just doesn’t cut it.
So when you find yourself going with a procedural-based approach and using a Cursor like a foreach loop, be sure to check out the the available attributes for Cursors to boost performance.
I found that adding the following attributes to one of my cursors shaved a modest 7 seconds off of a long running report:
DECLARE c CURSOR LOCAL FAST_FORWARD
Source:
MSDN: DECLARE CURSOR (Transact-SQL)
Further Reading:
Set-Based vs. Procedural
Procedural versus Set-Based SQL