Search tasks (advanced filters)
Search tasks with filters similar to the Asana search UI. You can filter by search text, projects, due date (exact or range), whether the task has an attachment, and date filters such as created or completed. Relative dates (e.g. start of year plus one day, or now minus 10 hours) are supported.
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.
--//search text in task title or description
SELECT * FROM search_tasks WITH(Text='Hotfix')
--//search text in all tasks from any projects listed below
SELECT * FROM search_tasks WITH(Text='Hotfix', ProjectsAny='1200652735638082,1206028542305053')
--//list all tasks from any projects listed below
SELECT * FROM search_tasks WITH(ProjectsAny='1200652735638082,1206028542305053')
--//list all tasks due on specified date (same way you can use CreatedOn, CompletedOn ...)
SELECT * FROM search_tasks WITH(DueOn='2024-12-21')
--//list all tasks with due date after specified date (same way you can use CreatedOnAfter, CompletedOnAfter ...)
SELECT * FROM search_tasks WITH(DueOnAfter='2024-12-21')
SELECT * FROM search_tasks WITH(DueOnAfter='yearstart+1d')
--//list all tasks with due date after specified date (same way you can use CreatedOnBefore, CompletedOnBefore ...)
SELECT * FROM search_tasks WITH(DueOnBefore='2024-12-21')
SELECT * FROM search_tasks WITH(DueOnBefore='monthstart-5d')
--//list all tasks with due date after specified datetime (same way you can use CreatedAtBefore, CompletedAtBefore ...)
SELECT * FROM search_tasks WITH(DueAtBefore='2024-12-21T23:59:59')
SELECT * FROM search_tasks WITH(DueAtBefore='now-10h')
--//list all tasks with attachment
SELECT * FROM search_tasks WITH(HasAttachment='true')
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_ASANA_IN_GATEWAY], '--//search text in task title or description
SELECT * FROM search_tasks WITH(Text=''Hotfix'')
--//search text in all tasks from any projects listed below
SELECT * FROM search_tasks WITH(Text=''Hotfix'', ProjectsAny=''1200652735638082,1206028542305053'')
--//list all tasks from any projects listed below
SELECT * FROM search_tasks WITH(ProjectsAny=''1200652735638082,1206028542305053'')
--//list all tasks due on specified date (same way you can use CreatedOn, CompletedOn ...)
SELECT * FROM search_tasks WITH(DueOn=''2024-12-21'')
--//list all tasks with due date after specified date (same way you can use CreatedOnAfter, CompletedOnAfter ...)
SELECT * FROM search_tasks WITH(DueOnAfter=''2024-12-21'')
SELECT * FROM search_tasks WITH(DueOnAfter=''yearstart+1d'')
--//list all tasks with due date after specified date (same way you can use CreatedOnBefore, CompletedOnBefore ...)
SELECT * FROM search_tasks WITH(DueOnBefore=''2024-12-21'')
SELECT * FROM search_tasks WITH(DueOnBefore=''monthstart-5d'')
--//list all tasks with due date after specified datetime (same way you can use CreatedAtBefore, CompletedAtBefore ...)
SELECT * FROM search_tasks WITH(DueAtBefore=''2024-12-21T23:59:59'')
SELECT * FROM search_tasks WITH(DueAtBefore=''now-10h'')
--//list all tasks with attachment
SELECT * FROM search_tasks WITH(HasAttachment=''true'')')
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_ASANA_IN_GATEWAY] syntax.
DECLARE @MyQuery NVARCHAR(MAX) = '--//search text in task title or description
SELECT * FROM search_tasks WITH(Text=''Hotfix'')
--//search text in all tasks from any projects listed below
SELECT * FROM search_tasks WITH(Text=''Hotfix'', ProjectsAny=''1200652735638082,1206028542305053'')
--//list all tasks from any projects listed below
SELECT * FROM search_tasks WITH(ProjectsAny=''1200652735638082,1206028542305053'')
--//list all tasks due on specified date (same way you can use CreatedOn, CompletedOn ...)
SELECT * FROM search_tasks WITH(DueOn=''2024-12-21'')
--//list all tasks with due date after specified date (same way you can use CreatedOnAfter, CompletedOnAfter ...)
SELECT * FROM search_tasks WITH(DueOnAfter=''2024-12-21'')
SELECT * FROM search_tasks WITH(DueOnAfter=''yearstart+1d'')
--//list all tasks with due date after specified date (same way you can use CreatedOnBefore, CompletedOnBefore ...)
SELECT * FROM search_tasks WITH(DueOnBefore=''2024-12-21'')
SELECT * FROM search_tasks WITH(DueOnBefore=''monthstart-5d'')
--//list all tasks with due date after specified datetime (same way you can use CreatedAtBefore, CompletedAtBefore ...)
SELECT * FROM search_tasks WITH(DueAtBefore=''2024-12-21T23:59:59'')
SELECT * FROM search_tasks WITH(DueAtBefore=''now-10h'')
--//list all tasks with attachment
SELECT * FROM search_tasks WITH(HasAttachment=''true'')'
EXEC (@MyQuery) AT [LS_TO_ASANA_IN_GATEWAY]