How do I put the results from an SQL Query into a chart?
Asked by Justin Zhao:

Hi everyone, I'm trying to put the results of an SQL Query into a chart. I've included screenshots of my expected outcome and my outcome below.

Regards,

Justin

Expected Outcome

<https://ibb.co/4V1TGGY>

Outcome

<https://ibb.co/fHD6bdR>


Answers:
author: Katerina Rudkovskaya [Stiltsoft]
body: Hi [@Justin Zhao](/t5/user/viewprofilepage/user-id/5097628),  

As I see from your screenshot, you are using the [Chart from Table](https://docs.stiltsoft.com/display/TFAC/How+to+use+Chart+from+Table+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro: it means that you have our [Table Filter and Charts for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence?hosting=cloud&tab=overview&utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) app installed for your instance.  

The mistake that you've got speaks for itself: the macro doesn't see the table inside its body.  
It is not very clear how you are trying to process the SQL query, but the pattern should be as following:  

Wrap your table in the [Table Toolbox](https://docs.stiltsoft.com/display/TFAC/How+to+use+Table+Toolbox+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro  

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

Go to the Table Toolbox macro settings and wrap your table subsequently in the [Table Transformer](https://docs.stiltsoft.com/display/TFAC/How+to+use+Table+Transformer+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro and in the Chart from Table macro.  

![Fri 3-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/229841i18B2230CA8B67F1E/image-size/large?v=v2&px=999 "Fri 3-2.png")  

The Table Transformer macro helps you to apply SQL query to your table (transform it and perform different calculations).  

For example, here I just add 20 to the "Number" column:  
SELECT T1.'Fruit',  
T1.'Number' + 20 AS 'New Number'  
FROM T\*  

![Fri 3-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/229842i355F15DC00608849/image-size/large?v=v2&px=999 "Fri 3-3.png")  

The Chart from Table macro allows you to build a chart based on the transformed table.  

![Fri 3-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/229843iBCFD6A67047AF64B/image-size/large?v=v2&px=999 "Fri 3-4.png")  

Hope it helps your case.  

If you are stuck with a query for the Table Transformer macro, you may always refer to our [support portal](https://jsd.stiltsoft.com/plugins/servlet/customer/portal/nologin?id=2/user/login?destination=portal%2F2%3Ffrom%3Dmacro). It is confidential, so you may freely attach a screenshot of your original table, describe what exactly you need to achieve, and we'll provide you with a suitable code.

comments: author: Justin Zhao
body: Thank you very much for the tips and advice, Katerina Rudkovskaya Stiltsoft. I'll try what you sent me out now. :D


author: Justin Zhao
body: Hi [@Katerina Rudkovskaya \[Stiltsoft\]](/t5/user/viewprofilepage/user-id/3738229) ,

I'm having issues putting the following SQL Query in the Table Transformer.

Regards,

Justin

```
USE cafeorderDECLARE @DateTimeNow DATETIME = dbo.GETDATE_SYDNEY()SELECT  substring(DATENAME(month, OrderDateTime), 0, 4) + '-' + substring(cast(year(OrderDateTime) as CHAR( 4)),3, 2) AS [Month],  sum(TotalCost) AS [Total Order Value], MONTH(OrderDateTime) as [Month], YEAR(OrderDateTime) as [Year]FROM  PatronsOrderwhere YEAR(OrderDateTime) >= YEAR(GETDATE()) -4 and MerchantId >= 1000 and PrintJobStatus = ('P') AND IsCancelled = 0 --and OrderDateTime < DATEADD(month, DATEDIFF(month, 0, @DateTimeNow), 0)GROUP BY DATENAME(month, OrderDateTime), MONTH(OrderDateTime), YEAR(OrderDateTime)order by YEAR(OrderDateTime), MONTH(OrderDateTime)
```


author: Katerina Rudkovskaya [Stiltsoft]
body: As I've mentioned before, let's move to the [support portal](https://jsd.stiltsoft.com/servicedesk/customer/portal/2/user/login?destination=portal%2F2).Give us a screenshot of your source table (without any macros and with visible headers). We'll recrete it in our test environment.Then describe what you want to achieve with the SQL query. The Table Transformer macro is based on the AlaSQL query, so the syntax may be different from yours.


author: Justin Zhao
body: Hi [@Katerina Rudkovskaya \[Stiltsoft\]](/t5/user/viewprofilepage/user-id/3738229) ,

I've been trying to sign up to the support portal, but I'm not getting an email to sign up with. Any fix around that?

Regards,

Justin


author: Katerina Rudkovskaya [Stiltsoft]
body: Hi [@Justin Zhao](/t5/user/viewprofilepage/user-id/5097628),   

I see that you've already raised the ticket. I suppose you could find the message, right?


author: Justin Zhao
body: Hi [@Katerina Rudkovskaya \[Stiltsoft\]](/t5/user/viewprofilepage/user-id/3738229) ,

I've managed to find the message. I'm currently trying to provide the information required to solve the problem.

Regards,

Justin


Tags: cloud

confluence-cloud