SQL Server guide

Read comments for issues by JQL


Gets all comments for issues that match a JQL expression. The connector first finds issues with the given JQL, then returns comments for those issues. Use the same JQL syntax as in the “Read issues using JQL query” example.

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 Comments WITH (Jql='status IN (Done, Closed) AND created > -5d' )

Using OPENQUERY in SQL Server

SELECT * FROM OPENQUERY([LS_TO_JIRA_IN_GATEWAY], 'SELECT * FROM Comments WITH (Jql=''status IN (Done, Closed) AND created > -5d'' )')

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_JIRA_IN_GATEWAY] syntax.

DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Comments WITH (Jql=''status IN (Done, Closed) AND created > -5d'' )'
EXEC (@MyQuery) AT [LS_TO_JIRA_IN_GATEWAY]