Table Transformer SQL - displaying multiple matches
Asked by Scott Gillespie:

I have 2 tables, T1 with 'Sprint Start Date' and 'Sprint End Date' and T2 with 'Holiday Short Date' and 'Holiday' fields. I want to compare the 2 tables, and find any holidays in T2 that fall between the Sprint Start Date and Sprint End Date.

If there is a match, a table should be displayed with the heading "Reminder: Supplier Holidays This Sprint" and a data field showing the holiday date "Holiday Short Date" and the holiday name 'Holiday'.

I thought this would be fairly simple but struggled to get correct results in every case. The following code was adjusted based on AI input, and worked almost correctly, except for 2 issues:

1. If more than one holiday found, commas appeared before every line after the first line.  
2. If no holidays found, the text message "No holidays" was not displayed--the data cell was blank. However, if multiple holidays were found, they would be listed correctly on separate lines, but with the leading comma.

Oddly, the GROUP_CONCAT function was accepted even though it's not listed as a supported function for Table Transformer.

Original Solution

SELECT  
CASE  
WHEN COUNT(\*) = 0 THEN "No holidays"  
ELSE  
FORMATWIKI(GROUP_CONCAT(CONCAT(FORMATDATE(T2.'Holiday Short Date', '%b %d, %Y') + ": " + T2.'Holiday' + "\\n")))  
END AS 'Reminder: Supplier Holidays This Sprint'  
FROM T1  
LEFT JOIN T2 ON T2.'Holiday Short Date' \>= T1.'Sprint Start Date'  
AND T2.'Holiday Short Date' \<= T1.'Sprint End Date'  
GROUP BY 'Reminder: Supplier Holidays This Sprint'

The alternate solution below resolved the comma issue and correctly displayed "No holiday" message, but then if more than one holiday match was found, only the first holiday would be displayed.

Alternate Solution

SELECT  
CASE  
WHEN (SELECT COUNT(\*) FROM T2 WHERE T2.'Holiday Short Date' \>= T1.'Sprint Start Date' AND T2.'Holiday Short Date' \<= T1.'Sprint End Date') = 0 THEN "No holidays"  
ELSE  
FORMATWIKI(REPLACE((SELECT FORMATDATE(T2.'Holiday Short Date', '%b %d, %Y') + ": " + T2.'Holiday' + CHAR(10)  
FROM T2  
WHERE T2.'Holiday Short Date' \>= T1.'Sprint Start Date'  
AND T2.'Holiday Short Date' \<= T1.'Sprint End Date'  
ORDER BY T2.'Holiday Short Date')))  
END AS 'Reminder: Supplier Holidays This Sprint'  
FROM T1

I'm sure I'm hitting all around the solution, but cannot get it right. Other research I do suggests using various functions not supported by Table Transformer such as XML PATH, STUFF, and STRING_AGG. So, time to come back to the experts here for guidance. Thanks in advance for any help you can provide.


Answers:
author: Stiltsoft support
body: Hi [@Scott Gillespie](/t5/user/viewprofilepage/user-id/5118135) ,

It seems that the question is about the [Table Filter, Charts \& Spreadsheets for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-charts-spreadsheets-for-confluence?tab=overview&hosting=datacenter&utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) app (that is our plugin) and its [Table Transformer](https://docs.stiltsoft.com/tfac/dc-server/table-transformer-42241552.html?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro.

If it is so and I've got your case correctly, you may try the following query:

![Thu 1-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/343323iF819D97AEE035B41/image-size/large?v=v2&px=999 "Thu 1-1.png")

SELECT 'Sprint',  
CASE  
WHEN (SELECT COUNT(\*) FROM T2 WHERE T2.'Holiday Short Date' \>= T1.'Sprint Start Date' AND T2.'Holiday Short Date' \<= T1.'Sprint End Date') = 0 THEN "No holidays"  
ELSE  
FORMATWIKI((SELECT **CONCAT_VIEW_AGGR** (FORMATDATE(T2.'Holiday Short Date', '%b %d, %Y') + ": " + T2.'Holiday' + ", ")  
FROM T2  
WHERE T2.'Holiday Short Date' \>= T1.'Sprint Start Date'  
AND T2.'Holiday Short Date' \<= T1.'Sprint End Date'  
ORDER BY T2.'Holiday Short Date'))  
END AS 'Reminder: Supplier Holidays This Sprint'  
FROM T1

![Thu 1-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/343324i2F479CF74AEC9AF9/image-size/large?v=v2&px=999 "Thu 1-2.png")

Hope it helps.


Tags: confluence-data-center

data-center

filter

table

table-filter

table-filter-and-charts

table-filter-charts-spreadsheets

table-transformer