Table transformer with conditional SQL selects
Asked by Marc_Sternberg:

Hello everyone,

I want to use the table transformer macro to execute two SQL selects depending on a condition.

If the Project row in the table shown is filled, the Select command should then execute a different select than if the row is not filled.

I have already tried the following. However, this does not work.

Thank you very much for your help!

![image.png](/t5/image/serverpage/image-id/290303i8DB89D3BFAA247B0/image-size/large?v=v2&px=999 "image.png")

```
DECLARE @projekt VARCHAR(255) = (SELECT T2.'Projekt' FROM T2);
IF (@projekt = "")
SELECT T2.'Sortiment',T2.'Produktbereich',T2.'Dokument',T2.'System',T2.'Status',T2.'Projekt' FROM T2
ELSE
SELECT T2.'Sortiment',T2.'Produktbereich',T2.'Dokument',T2.'System',T2.'Status',T2.'Projekt', CONCAT("15.",T1.'Verkaufsstart (SOD) Monat'::string->split("/")->1,".",T1.'Verkaufsstart (SOD)'::string->split("/")->0) AS 'Verkaufsstart' FROM T1,T2 WHERE T1.'Projekte' LIKE T2.'Projekt'
```

![image.png](/t5/image/serverpage/image-id/290304i4A355718ECC9C8FE/image-size/large?v=v2&px=999 "image.png")


Answers:
author: Marc - Devoteam
body: Hi [@Marc_Sternberg](/t5/user/viewprofilepage/user-id/5357984)

I would suggest you reach out to the support portal of Stiltsoft. As they are the vendor and developer of the app.

They could be able to tell you if this is an option in there app r not and they might see this a bug or a feature request.

comments: author: Stiltsoft support
body: Hi [@Marc_Sternberg](/t5/user/viewprofilepage/user-id/5357984)

Please refer to our [support portal](https://stiltsoft.atlassian.net/servicedesk/customer/portal/14) as [@Marc - Devoteam](/t5/user/viewprofilepage/user-id/3796976) has kindly mentioned.

The Table Transformer macro is based on the AlaSQL library and includes some limited functions of the JavaScript, so all the cases should be implemented accordingly to their rules.

To apply the condition, we can use the [CASE WHEN statement](https://docs.stiltsoft.com/tfac/dc-server/custom-transformation-use-cases-with-advanced-sql-queries-42241587.html#CustomTransformationusecaseswithadvancedSQLqueries-UsingIf/Thenconstruct) from the AlaSQL library.

So, for us to help you with the SQL query, please attach the page storage of your page (upper right corner of the page -\> menu ... -\> View storage format). Then we'll be able to recreate exactly your page with macros, queries, and source tables.

I also see that you have the Table Excerpt Include macro inside the internal Table Transformer macro - please attach the page storage of the page with the corresponding Table Excerpt macro as well.

And from the query I can see that if the project name is empty, then you want to show the second table as it is. If it is not empty, then you want to show some extra data from the first table and you need to find this data by the project name. If I've got you wrong, please describe the desired result in the ticket as well.


author: Marc_Sternberg
body: Hello everyone,

Nikita has helped me to understand the Macro.  
I have placed an additional table transformer around the table, which now transposes the table.

With the following query it now works as desired.

```
DECLARE @projekt VARCHAR(255) = (SELECT T2.'Projekt' FROM T2);
IF (@projekt = "")
SELECT T2.'Sortiment',T2.'Produktbereich',T2.'Dokument',T2.'System',T2.'Status',T2.'Projekt' FROM T2
ELSE
SELECT T2.'Sortiment',T2.'Produktbereich',T2.'Dokument',T2.'System',T2.'Status',T2.'Projekt', CONCAT("15.",T1.'Verkaufsstart (SOD) Monat'::string->split("/")->1,".",T1.'Verkaufsstart (SOD)'::string->split("/")->0) AS 'Verkaufsstart' FROM T1,T2 WHERE T1.'Projekte' LIKE T2.'Projekt'
```

<br />

Thank you very much for your support.

Best wishes,

Marc


Tags: confluence-server

filter

server

table