ODBC guide

Read more than 20000 work items (UNION ALL)


The Azure DevOps API returns at most 20000 work items per request. To read more, run multiple queries that each request a different ID range (e.g. 1–19999, 20000–39999) and combine the results. This example uses temp tables and UNION ALL so you get one result set; you can add more ranges by adding more SELECT INTO and UNION ALL lines.

Run the full script at once. Adjust the ID ranges and the number of temp tables to match your data size.

SELECT * INTO #t1 FROM WorkItems WITH(Project='ProductTesting', Query='SELECT * FROM WorkItems WHERE [System.Id]>=1 and [System.Id]<20000');
SELECT * INTO #t2 FROM WorkItems WITH(Project='ProductTesting', Query='SELECT * FROM WorkItems WHERE [System.Id]>=20000 and [System.Id]<40000');
SELECT * INTO #t3 FROM WorkItems WITH(Project='ProductTesting', Query='SELECT * FROM WorkItems WHERE [System.Id]>=40000 and [System.Id]<60000');
--//....
--//add more temp tables above and update UNION ALL too

SELECT * FROM #t1 
UNION ALL 
SELECT * FROM #t2
UNION ALL 
SELECT * FROM #t3
;