I am looking for a way to execute an SQL script where I have two statements, a set and a select :
SET datefirst 1;
SELECT *
FROM (SELECT [book],
Datefromparts(Year(exposure_date), Month(exposure_date), 1) AS EXPOSURE_DATE,
Datepart(year, exposure_date) AS YEAR,
Datepart(month, exposure_date) AS MONTH,
Datepart(quarter, exposure_date) AS QUARTER,
[exposure]
FROM [REPORTING].[dbo].[v_exp_daily_gas_physfin_mapped]
WHERE risk_map = 'LCO'
AND book = 'tpvh'
AND report_asof_date = '2020-07-10') AS BASE
PIVOT(Sum(exposure)
FOR book IN ([TPVH])) AS pvt
ORDER BY exposure_date;
If I try to fit this inside a SELECT statement it gives me the error that it expects a SELECT instead of the SET statement (i.e. "Query type must be one of [SELECT, STORE_PROCEDURE_CALL] but query 'SET datefirst 1;
).
Now, I understand that what I need for my multiple SQL queries is a Database "Execute Script" block from the Mule Palette.
But when I try to execute the code inside it, it gives me the following error : "A result set was generated for update."
The connection to the database works OK as it can be seen :
I did check the following link (the official documentation) : https://docs.mulesoft.com/db-connector/1.11/database-execute-script but it does not help :(
Does anyone has a clue ? Many thanks !