Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have the following requirement:
1.User selects Year (single value) and Month (multiple values) from the filters in a sheet
2.User clicks on Reload button (Button Chart Type), which then passes the values to the Data Load scripts
3.The SQL query in Data Load script has 'Year' and 'Month' in the WHERE condition and single/multiple values needs to be passed. I guess it would be something like this.
SELECT COUNT(OrderID) NoOfOrders, SUM(OrderAmount) OrderAmount
FROM Orders
WHERE TO_CHAR(OrderDate,'YYYY') = '$(vYearID)'
AND TO_CHAR(OrderDate,'MM') IN '$(vMonthID)'
Would the IN condition work in the SQL query, if the vMonthID is populated as 9,10,11?
Can someone please share the steps or a sample file for reference?
Many Thanks !!
Hi @anat
Thanks for your reply. When I am selecting the filter, the multiple values are already comings with a comma delimiter. The issue was with the SQL formation.
The curly brackets after the IN statement needs to be explicitly defined for the SQL to work. I changed the SQL query to the one below and then it worked.
SELECT COUNT(OrderID) NoOfOrders, SUM(OrderAmount) OrderAmount
FROM Orders
WHERE TO_CHAR(OrderDate,'YYYY') = $(vYear)
AND TO_CHAR(OrderDate,'MM') IN ( $(vMonth) )
Thanks once again for looking into it.
Hi,
Please note that I am able to refresh the data in the SQL when there is only 1 value in the variables vYear and vMonth variables. The following works...
vYear = GetFieldSelections(YearID);
vMonth = GetFieldSelections(MonthID);
The above variables are set in the Reload button configuration under 'Actions and Navigation'.
SELECT COUNT(OrderID) NoOfOrders, SUM(OrderAmount) OrderAmount
FROM Orders
WHERE TO_CHAR(OrderDate,'YYYY') = $(vYear)
AND TO_CHAR(OrderDate,'MM') = $(vMonth)
The issue comes when there are multiple values selected from the filter. For example if I select Months 9,10 and 11 from the filter then the SQL query fails on click of Reload button because the IN condition doesn't work.
SELECT COUNT(OrderID) NoOfOrders, SUM(OrderAmount) OrderAmount
FROM Orders
WHERE TO_CHAR(OrderDate,'YYYY') = $(vYear)
AND TO_CHAR(OrderDate,'MM') IN $(vMonth)
How can I make the SQL to work with a IN condition when the variable vMonth is having multiple values?
Kindly help.
Hi @satya_s
Try using the CONCAT() function to get all values in the month field into a comma separated list and pass it in the IN statement. See if that works
vMonth = concat(GetFieldSelections(MonthID),',')
Best
Björn
use concat function to store multiple values in variable
Concat(DISTINCT GetFieldSelections(Month),', ')
It depends mainly on the from the data-base supported syntax. I suggest you comment the month-variable at first and writes two month manually within the in() or in "...." or whatever the data-base recognized. If it worked you shows the variable-content within a text-box until it looked like your hard-coded values.
Hi @anat
Thanks for your reply. When I am selecting the filter, the multiple values are already comings with a comma delimiter. The issue was with the SQL formation.
The curly brackets after the IN statement needs to be explicitly defined for the SQL to work. I changed the SQL query to the one below and then it worked.
SELECT COUNT(OrderID) NoOfOrders, SUM(OrderAmount) OrderAmount
FROM Orders
WHERE TO_CHAR(OrderDate,'YYYY') = $(vYear)
AND TO_CHAR(OrderDate,'MM') IN ( $(vMonth) )
Thanks once again for looking into it.
Hi Marcus,
Thanks for your reply. I managed to make it work by explicitly putting the curly brackets in the SQL.
SELECT COUNT(OrderID) NoOfOrders, SUM(OrderAmount) OrderAmount
FROM Orders
WHERE TO_CHAR(OrderDate,'YYYY') = $(vYear)
AND TO_CHAR(OrderDate,'MM') IN ( $(vMonth) )
Thanks once again for looking into it.