Query work items modified after a date (dynamic)
Use placeholder functions (e.g. monthstart, today, yearend) and arithmetic (e.g. monthstart-1d) to build dynamic dates in your WIQL query so the same statement always reflects the intended period without manual date changes. The placeholder is evaluated before the query is sent to Azure DevOps.
For placeholder syntax and options see placeholder functions. For WIQL see WIQL syntax.
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 WorkItems WITH (Query='SELECT * FROM WorkItems
WHERE [System.TeamProject]=''ProductTesting''
AND [System.ChangedDate] >= ''<<monthstart-1d,FUN_TO_DATE>>''
ORDER BY [System.ChangedDate] DESC
')
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_AZURE_DEVOPS_IN_GATEWAY], 'SELECT * FROM WorkItems WITH (Query=''SELECT * FROM WorkItems
WHERE [System.TeamProject]=''''ProductTesting''''
AND [System.ChangedDate] >= ''''<<monthstart-1d,FUN_TO_DATE>>''''
ORDER BY [System.ChangedDate] DESC
'')')
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 WorkItems WITH (Query=''SELECT * FROM WorkItems
WHERE [System.TeamProject]=''''ProductTesting''''
AND [System.ChangedDate] >= ''''<<monthstart-1d,FUN_TO_DATE>>''''
ORDER BY [System.ChangedDate] DESC
'')'
EXEC (@MyQuery) AT [LS_TO_AZURE_DEVOPS_IN_GATEWAY]