How to Fix DECLARE CURSOR Is Not Supported Error in Microsoft Fabric
Question details
The user needs a supported alternative or replacement for cursor-based SQL queries in Microsoft Fabric.

- Product
- Microsoft Fabric
- Device & OS
- not provided
- Scenario
- Executing a SQL script or stored procedure that relies on cursors for row-by-row data processing.
- Observed behavior
- The system throws an error stating 'DECLARE CURSOR is not supported', which prevents the query from running.
Review your SQL query to identify the specific row-by-row operations being performed, as distributed architectures like Microsoft Fabric are optimized for set-based logic rather than iterative loops.
Rewrite the Query Using Set-Based Operations
Replacing the cursor with set-based SQL operations is the most efficient and native way to handle data transformations in Microsoft Fabric.
Distributed data warehouses like Microsoft Fabric process data across multiple nodes in parallel. Cursors enforce single-threaded, row-by-row processing, which is why they are unsupported. Set-based logic solves this by processing large chunks of data simultaneously.
Analyze the logic inside your cursor loop to determine if it is updating records, inserting data, or calculating running totals.
Rewrite the cursor loop into a single, comprehensive `UPDATE ... FROM ... JOIN` or `INSERT INTO ... SELECT` statement to process all rows at once.
If the cursor is being used for sequential calculations or running totals, use T-SQL window functions like `ROW_NUMBER()`, `SUM() OVER()`, or `LAG()` to achieve the same result without looping.

Simulate a Cursor Using a WHILE Loop
If complex procedural logic prevents you from using set-based operations, you can simulate cursor behavior using a WHILE loop with a temporary table.
Consult Microsoft Q&A for Complex Architecture
If your legacy code relies heavily on complex nested cursors, you may need guidance from Microsoft support engineers to re-architect your data processing logic.
Manage Your Technical Documentation with WPS Office
While troubleshooting SQL errors and migrating databases in Microsoft Fabric, you need a reliable office suite to document query designs, architectures, and project plans. WPS Office is a completely free, lightweight alternative that meets all your professional documentation needs.
- 1. Download the software: Visit the WPS Office website and download the free installation package for your operating system.
- 2. Install WPS Office: Run the downloaded installer and follow the on-screen prompts to complete the setup process in minutes.
- 3. Start documenting: Open WPS Writer or Spreadsheets to begin seamlessly documenting your Microsoft Fabric query designs and project plans.

Frequently Asked Questions
Why is DECLARE CURSOR not supported in Microsoft Fabric?
Microsoft Fabric uses a distributed, parallel processing architecture designed to handle massive amounts of data across multiple computing nodes simultaneously. Cursors enforce single-threaded, row-by-row processing, which defeats the purpose of distributed computing and causes severe performance bottlenecks.
Are stored procedures supported in Microsoft Fabric?
Yes, stored procedures are fully supported in Microsoft Fabric data warehouses. However, the T-SQL logic inside those stored procedures must be supported by the platform. Any existing cursors inside your stored procedures must be rewritten using set-based operations or WHILE loops.
Is there any plan to support cursors in Microsoft Fabric in the future?
Currently, Microsoft has no official roadmap to support traditional T-SQL cursors in the Fabric data warehouse workload, as the underlying architecture is fundamentally optimized for set-based parallel execution.
What is the best alternative to a cursor for running totals?
The most efficient alternative to a cursor for calculating running totals is using SQL window functions, specifically the `SUM() OVER(ORDER BY column_name)` syntax, which is fully supported and highly optimized in Microsoft Fabric.




