I'm trying to pass a value from a CTE to my function (UDF). Unfortunately, it's not working. Here is the first variant:
WITH fx_date_new AS (
SELECT CASE
WHEN '2025-01-01' > current_date()
THEN CAST(date_format(add_months(current_date(), -1), 'yyyyMM') AS INT)
ELSE CAST(date_format(add_months('2025-01-01', -1), 'yyyyMM') AS INT)
END AS fxdate
)
select calcccy (1000,
'USD',
'EUR',
select fxdate from fx_date_new
);
The second variant with INNER JOIN/CROSS APPLY:
WITH fx_date_new AS (
SELECT CASE
WHEN '2025-01-01' > current_date()
THEN CAST(date_format(add_months(current_date(), -1), 'yyyyMM') AS INT)
ELSE CAST(date_format(add_months('2025-01-01', -1), 'yyyyMM') AS INT)
END AS fxdate
)
SELECT
fx_date_new.fxdate,
UDF.*
FROM
fx_date_new
INNER JOIN -- or CROSS APPLY
gold.calcccy(
1000,
'USD',
'EUR',
fx_date_new.fxdate
) AS UDF;
Neither of the two variants works.
Error: A column, variable, or function parameter with name fx_date_new.fxdate cannot be resolved
Do you have any idea how I can solve this?