SQL Server guide

Get work items by IDs (comma-separated)


Returns multiple work items in one request by passing a comma-separated list of IDs in the WITH clause. Useful when you have a fixed set of IDs (e.g. from a report or link) and want to load full details without running a WIQL query. The result set includes all columns for each work item.

Standard SQL query example

This is the base query accepted by the connector. To execute it in SQL Server, you have to pass it to the Data Gateway via a Linked Server. See how to accomplish this using the examples below.

SELECT * FROM get_workitems_by_ids WITH (ids='6444,5578,9467')

Using OPENQUERY in SQL Server

SELECT * FROM OPENQUERY([LS_TO_AZURE_DEVOPS_IN_GATEWAY], 'SELECT * FROM get_workitems_by_ids WITH (ids=''6444,5578,9467'')')

Using EXEC in SQL Server (handling larger SQL text)

The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements. This often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).

Fortunately, starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY] syntax.

DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM get_workitems_by_ids WITH (ids=''6444,5578,9467'')'
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY]