I have an SQL server database hosted on Microsoft Azure with MS Access as the front end. I have written a query in SSMS 18.8 as follows
SELECT p.Full_Citation AS [Full Citation], p.Reference, p.StudyID AS [Study ID], t.RefID AS [Database Reference], p.Primary_Secondary_Source AS [Primary/Secondary], p.Linked_Publications AS [Linked Publications],
p.Publication_Type AS [Publication Type], STRING_AGG(STUFF(COALESCE(' ' + Trial_Name, '') + COALESCE(' ' + Trial_Number, ''), 1, 1, ''), ', ') AS Trials
FROM FTS_Trials t
INNER JOIN Papers p
ON p.RefID = t.RefID
WHERE p.Project = 'TST_TST_1'
GROUP BY p.Full_Citation, p.Reference, p.StudyID, t.RefID, p.Primary_Secondary_Source, p.Linked_Publications, p.Publication_Type;
This produces the following output:
Full Citation | Reference | Study ID | Database Reference | Primary/Secondary | Linked Publications | Publication Type | Trials | |
---|---|---|---|---|---|---|---|---|
1 | NULL | NULL | Testing (2021) | TST_TST_1-1-Testing (2021) | NULL | NULL | NULL | 85, Example, Test 1 |
2 | NULL | NULL | Testing (2019) | TST_TST_1-2-Testing (2019) | NULL | NULL | NULL | Test 2 |
The problem I am having is that when I try to run this code in SQL view of the queries in MS Access it comes up "Undefined function 'STRING_AGG' in expression.". Can anyone shed some light as to why this works in SSMS but not in Access and am I missing something glaringly obvious?
I have also tried a different approach using only the STUFF() function in a similar manner to the first answer on this question T-SQL Concatenate & group multiple rows into a single row . Again this works fine in SSMS but MS Access is telling me there is a query error in the syntax. In addition this query did not combine Trial_Name and Trial_Number like the one above does. Is there another approach I can take using MS Access?
For a little bit of background the query is going to be attached to a button that the user clicks which ideally needs to show the query and then export it to an Excel file. I have set this up for other queries but wanting to concatenate all trials (Trial_Name + Trial_Number) for a given citation in one row has made this scenario much trickier to solve.