SQL Server guide

Read worklogs modified after a date


Gets worklog entries that were modified after a given date/time. Use the get_worklogs_after table and set UpdatedAfter in WITH; the date is interpreted in the site timezone. You can use a static date or a function (e.g. today-1d, now-24h). Optionally narrow by issue using JQL, Project, or Key.

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_worklogs_after
WITH(
	--#### Worklog Filter #####
	  UpdatedAfter='2024-08-23' --only fetch work logs modified after this date/time is Site Timezone
	--OR--
	--UpdatedAfter='2024-08-23T17:03:26.079' --with time part
	--OR--
	--UpdatedAfter='today-1d' --with function. For more information about functions, see https://zappysys.com/links/?id=10014 (Look for FUN_TO_DATETIME)
    --UpdatedAfter='monthstart+7d' 
	--UpdatedAfter='now-24h' 
    
	--#### Issue Filter (Optional) #####
    --Search issues by Project / JQL expression / Issue Keys. If not specified all issues returned
	--,JQL='key IN(CS-1, CS-2, CS-3)' 
	--,Project='PRJ1,PRJ2' 
	--,Key='CS-1,CS-2,CS-3' 
)

Using OPENQUERY in SQL Server

SELECT * FROM OPENQUERY([LS_TO_JIRA_IN_GATEWAY], 'SELECT * FROM get_worklogs_after
WITH(
	--#### Worklog Filter #####
	  UpdatedAfter=''2024-08-23'' --only fetch work logs modified after this date/time is Site Timezone
	--OR--
	--UpdatedAfter=''2024-08-23T17:03:26.079'' --with time part
	--OR--
	--UpdatedAfter=''today-1d'' --with function. For more information about functions, see https://zappysys.com/links/?id=10014 (Look for FUN_TO_DATETIME)
    --UpdatedAfter=''monthstart+7d'' 
	--UpdatedAfter=''now-24h'' 
    
	--#### Issue Filter (Optional) #####
    --Search issues by Project / JQL expression / Issue Keys. If not specified all issues returned
	--,JQL=''key IN(CS-1, CS-2, CS-3)'' 
	--,Project=''PRJ1,PRJ2'' 
	--,Key=''CS-1,CS-2,CS-3'' 
)')

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 get_worklogs_after
WITH(
	--#### Worklog Filter #####
	  UpdatedAfter=''2024-08-23'' --only fetch work logs modified after this date/time is Site Timezone
	--OR--
	--UpdatedAfter=''2024-08-23T17:03:26.079'' --with time part
	--OR--
	--UpdatedAfter=''today-1d'' --with function. For more information about functions, see https://zappysys.com/links/?id=10014 (Look for FUN_TO_DATETIME)
    --UpdatedAfter=''monthstart+7d'' 
	--UpdatedAfter=''now-24h'' 
    
	--#### Issue Filter (Optional) #####
    --Search issues by Project / JQL expression / Issue Keys. If not specified all issues returned
	--,JQL=''key IN(CS-1, CS-2, CS-3)'' 
	--,Project=''PRJ1,PRJ2'' 
	--,Key=''CS-1,CS-2,CS-3'' 
)'
EXEC (@MyQuery) AT [LS_TO_JIRA_IN_GATEWAY]