Query Work Items
Name
query_workitems
Description
Get work items associated with the specified project and organization that are filtered by a Wiql query. (A team can optionally be specified as well.). Read more about this API here https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/wiql/query-by-wiql?view=azure-devops-rest-7.0 and here https://learn.microsoft.com/en-us/azure/devops/boards/queries/query-operators-variables?view=azure-devops [API reference]
Related Tables
Parameters
Parameter | Label | Required | Options | Description | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Project | Project Name | YES | The Name of the project. | |||||||
Query | Wiql Query | YES | The WIQL query (refer Azure DevOps Help to learn Wiql syntax. [API reference] | |||||||
Team | Team Id or Name | NO | Id or name of the team associated with the query. | |||||||
TimePrecision | Use time precision | NO |
|
Whether or not to use time precision. |
Output Columns
Label | Data Type (SSIS) | Data Type (SQL) | Length | Raw | Description |
---|---|---|---|---|---|
Id |
DT_I4
|
int
|
False |
||
Title |
DT_WSTR
|
nvarchar(1000)
|
1000 | False |
|
Description |
DT_WSTR
|
nvarchar(4000)
|
4000 | False |
|
WorkItemType |
DT_WSTR
|
nvarchar(100)
|
100 | False |
|
State |
DT_WSTR
|
nvarchar(100)
|
100 | False |
|
Url |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
Tags |
DT_WSTR
|
nvarchar(4000)
|
4000 | False |
|
Revision |
DT_I4
|
int
|
False |
||
AreaPath |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
TeamProject |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
IterationPath |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
Reason |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
CreatedDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
ChangedDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
CommentCount |
DT_I4
|
int
|
False |
||
AssignedToDisplayName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
AssignedToUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
AssignedToLinksAvatarHref |
DT_WSTR
|
nvarchar(4000)
|
4000 | False |
|
AssignedToId |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
AssignedToUniqueName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
AssignedToImageUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
AssignedToDescriptor |
DT_WSTR
|
nvarchar(2000)
|
2000 | False |
|
CreatedByDisplayName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
CreatedByUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
CreatedByLinksAvatarHref |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
CreatedById |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
CreatedByUniqueName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
CreatedByImageUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
CreatedByDescriptor |
DT_WSTR
|
nvarchar(2000)
|
2000 | False |
|
ChangedByDisplayName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ChangedByUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ChangedByLinksAvatarHref |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ChangedById |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ChangedByUniqueName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ChangedByImageUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ChangedByDescriptor |
DT_WSTR
|
nvarchar(2000)
|
2000 | False |
|
Watermark |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
StateChangeDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
Priority |
DT_I4
|
int
|
False |
||
Triage |
DT_WSTR
|
nvarchar(1000)
|
1000 | False |
|
StackRank |
DT_I4
|
int
|
False |
||
Blocked |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
TaskType |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
RequiresReview |
DT_WSTR
|
nvarchar(100)
|
100 | False |
|
RequiresTest |
DT_WSTR
|
nvarchar(100)
|
100 | False |
|
ActivatedDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
ActivatedByDisplayName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ActivatedByUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ActivatedByLinksAvatarHref |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ActivatedById |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ActivatedByUniqueName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ActivatedByImageUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ActivatedByDescriptor |
DT_WSTR
|
nvarchar(2000)
|
2000 | False |
|
ClosedDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
ClosedByDisplayName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ClosedByUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ClosedByLinksAvatarHref |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ClosedById |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ClosedByUniqueName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ClosedByImageUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ClosedByDescriptor |
DT_WSTR
|
nvarchar(2000)
|
2000 | False |
|
ResolvedDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
ResolvedByDisplayName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ResolvedByUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ResolvedByLinksAvatarHref |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ResolvedById |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ResolvedByUniqueName |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
ResolvedByImageUrl |
DT_WSTR
|
nvarchar(2048)
|
2048 | False |
|
ResolvedByDescriptor |
DT_WSTR
|
nvarchar(2000)
|
2000 | False |
|
ResolvedReason |
DT_WSTR
|
nvarchar(4000)
|
4000 | False |
|
AreaId |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
IterationId |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
RevisedDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
RemoteLinkCount |
DT_I4
|
int
|
False |
||
RelatedLinkCount |
DT_I4
|
int
|
False |
||
HyperLinkCount |
DT_I4
|
int
|
False |
||
ExternalLinkCount |
DT_I4
|
int
|
False |
||
History |
DT_WSTR
|
nvarchar(2000)
|
2000 | False |
|
IntegrationBuild |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
FoundIn |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
OriginalEstimate |
DT_R4
|
real
|
False |
||
RemainingWork |
DT_R4
|
real
|
False |
||
CompletedWork |
DT_R4
|
real
|
False |
||
Size |
DT_R4
|
real
|
False |
||
Effort |
DT_R4
|
real
|
False |
||
TargetDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
StoryPoints |
DT_R4
|
real
|
False |
||
StartDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
FinishDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
DueDate |
DT_DBTIMESTAMP
|
datetime
|
False |
||
Discipline |
DT_WSTR
|
nvarchar(500)
|
500 | False |
|
SystemInfo |
DT_WSTR
|
nvarchar(4000)
|
4000 | False |
|
Steps |
DT_WSTR
|
nvarchar(4000)
|
4000 | False |
|
ReproSteps |
DT_WSTR
|
nvarchar(4000)
|
4000 | False |
|
[$parent.referenceName$] |
DT_WSTR
|
nvarchar(4000)
|
4000 | False |
Input Columns
Label | Data Type (SSIS) | Data Type (SQL) | Length | Raw | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
There are no Static columns defined for this endpoint. This endpoint detects columns dynamically at runtime. |
Examples
SSIS
Use Azure DevOps Connector in API Source component to read data or in API Destination component to read/write data:
Read from WorkItems table using API Destination
This Endpoint belongs to WorkItems table, therefore you cannot work with it directly. Use this table and table-operation pair instead:

ODBC application
Use these SQL queries in your ODBC application data source:
Query work items
SELECT * FROM query_workitems
WITH
(
"Project" = 'abcd-1234-project',
"Query" = 'SELECT * FROM WorkItems Order By [System.Id] DESC'
)
Get work items for the default project(specified by connection settings)
SELECT * FROM WorkItems
Get work items for the specific project
SELECT * FROM WorkItems WITH (Project='ProductTesting')
Create a query to get work items by the Id of the work items in the default project for the organization
To learn more about Query syntax refer to this link https://learn.microsoft.com/en-us/azure/devops/boards/queries/wiql-syntax?view=azure-devops and this link https://learn.microsoft.com/en-us/azure/devops/boards/queries/query-operators-variables?view=azure-devops
SELECT * FROM WorkItems WITH (Query='SELECT * FROM WorkItems
WHERE [System.Id] > 2000 AND [System.Id] < 7050
AND [System.TeamProject]=''ProductTesting''
AND [System.ChangedDate] < @Today
AND [System.CreatedDate] > @StartOfYear
AND [System.WorkItemType]=''Task''
AND [System.State]=''Resolved''
AND [Microsoft.VSTS.Common.Priority] >= 1
ORDER BY [System.ChangedDate] DESC
')
Create a query to get work items by the Id of the work items in the specified project for the organization
SELECT * FROM WorkItems WITH (Project='PosProject', Query='SELECT * FROM WorkItems WHERE [System.Id] = 2819')
Create a query to get work items by the types of work items in the default project for the organization
SELECT * FROM WorkItems WITH (Query='SELECT * FROM WorkItems WHERE [System.WorkItemType] = ''Task''')
Query work items using Wiql
This example shows how to use WIQL language to query Azure DevOps WorkItems. To learn more about WIQL Syntax you can refer this link https://learn.microsoft.com/en-us/azure/devops/boards/queries/wiql-syntax?view=azure-devops
SELECT
Id
, Title
, Description
, CreatedDate
, Url
FROM WorkItems
--WHERE Id=5283490 -- get just one comment for specific WorkItem Id
WITH(Query='SELECT * FROM WorkItems WHERE [System.TeamProject]=''ProductTesting'' and [System.Id]=6455 ORDER BY [System.Id] DESC')
Query Sprint Hours by Team Member - Esimated vs Actual Completed
This query shows how to query total time spent by team members during a specific Sprint (i.e. Iteration Path). This query only works if your team is updating Original Estimate and Completed Hours on work item after they are done with the task.
SELECT
IterationPath as Sprint
, AssignedToUniqueName as AssignedTo
, SUM(OriginalEstimate) as OriginalHours_Total
, SUM(RemainingWork) as RemainingWork_Total
, SUM(CompletedWork) as CompletedHours_Total
FROM WorkItems
GROUP BY IterationPath,AssignedToUniqueName
WITH(
Project='ProductTesting'
--//On Preview UI Change [Max Rows] to use more sample rows - else it will use only 100 rows
,Query='SELECT * FROM WorkItems WHERE [System.IterationPath] UNDER ''ProductTesting\Sprint 1'' and State IN(''Resolved'', ''Closed'')'
--Use below to query all sprints for this Product
--,Query='SELECT * FROM WorkItems WHERE [System.IterationPath] UNDER ''ProductTesting\'' and State IN(''Resolved'', ''Closed'')'
)
Read more than 20000 work items (UNION ALL)
By default Azure DevOps API returns max 20000 items. If you want more than 20000 items then you can try below technique. Run enire query at once. Basically it creates many temp table each consisting 20000 rows each and then in final query we do UNION ALL
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
;
query_workitems
endpoint belongs to
WorkItems
table(s), and can therefore be used via those table(s).
SQL Server
Use these SQL queries in SQL Server after you create a data source in Data Gateway:
Query work items
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM query_workitems
WITH
(
"Project" = ''abcd-1234-project'',
"Query" = ''SELECT * FROM WorkItems Order By [System.Id] DESC''
)';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
Get work items for the default project(specified by connection settings)
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM WorkItems';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
Get work items for the specific project
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM WorkItems WITH (Project=''ProductTesting'')';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
Create a query to get work items by the Id of the work items in the default project for the organization
To learn more about Query syntax refer to this link https://learn.microsoft.com/en-us/azure/devops/boards/queries/wiql-syntax?view=azure-devops and this link https://learn.microsoft.com/en-us/azure/devops/boards/queries/query-operators-variables?view=azure-devops
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM WorkItems WITH (Query=''SELECT * FROM WorkItems
WHERE [System.Id] > 2000 AND [System.Id] < 7050
AND [System.TeamProject]=''''ProductTesting''''
AND [System.ChangedDate] < @Today
AND [System.CreatedDate] > @StartOfYear
AND [System.WorkItemType]=''''Task''''
AND [System.State]=''''Resolved''''
AND [Microsoft.VSTS.Common.Priority] >= 1
ORDER BY [System.ChangedDate] DESC
'')';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
Create a query to get work items by the Id of the work items in the specified project for the organization
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM WorkItems WITH (Project=''PosProject'', Query=''SELECT * FROM WorkItems WHERE [System.Id] = 2819'')';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
Create a query to get work items by the types of work items in the default project for the organization
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM WorkItems WITH (Query=''SELECT * FROM WorkItems WHERE [System.WorkItemType] = ''''Task'''''')';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
Query work items using Wiql
This example shows how to use WIQL language to query Azure DevOps WorkItems. To learn more about WIQL Syntax you can refer this link https://learn.microsoft.com/en-us/azure/devops/boards/queries/wiql-syntax?view=azure-devops
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT
Id
, Title
, Description
, CreatedDate
, Url
FROM WorkItems
--WHERE Id=5283490 -- get just one comment for specific WorkItem Id
WITH(Query=''SELECT * FROM WorkItems WHERE [System.TeamProject]=''''ProductTesting'''' and [System.Id]=6455 ORDER BY [System.Id] DESC'')';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
Query Sprint Hours by Team Member - Esimated vs Actual Completed
This query shows how to query total time spent by team members during a specific Sprint (i.e. Iteration Path). This query only works if your team is updating Original Estimate and Completed Hours on work item after they are done with the task.
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT
IterationPath as Sprint
, AssignedToUniqueName as AssignedTo
, SUM(OriginalEstimate) as OriginalHours_Total
, SUM(RemainingWork) as RemainingWork_Total
, SUM(CompletedWork) as CompletedHours_Total
FROM WorkItems
GROUP BY IterationPath,AssignedToUniqueName
WITH(
Project=''ProductTesting''
--//On Preview UI Change [Max Rows] to use more sample rows - else it will use only 100 rows
,Query=''SELECT * FROM WorkItems WHERE [System.IterationPath] UNDER ''''ProductTesting\Sprint 1'''' and State IN(''''Resolved'''', ''''Closed'''')''
--Use below to query all sprints for this Product
--,Query=''SELECT * FROM WorkItems WHERE [System.IterationPath] UNDER ''''ProductTesting\'''' and State IN(''''Resolved'''', ''''Closed'''')''
)';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
Read more than 20000 work items (UNION ALL)
By default Azure DevOps API returns max 20000 items. If you want more than 20000 items then you can try below technique. Run enire query at once. Basically it creates many temp table each consisting 20000 rows each and then in final query we do UNION ALL
DECLARE @MyQuery NVARCHAR(MAX) = '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
;';
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY];
query_workitems
endpoint belongs to
WorkItems
table(s), and can therefore be used via those table(s).