I have a function which accepts 3 varchar inputs and returns 1 varchar output.
The function works quite well in SQL Server but not in Snowflake. I don't see what's wrong. Everything seems to be fine.
Note: it works fine when a string is passed but not when column is passed. I am not sure why it isn't accepting multiple rows??
SELECT Get_Status_Descriptiontest('can', '1', '2')
Below is the query:
with cte as (
select 'CAN' as a, 1 as b
union
select 'Ban' as a, 2 as b
)
SELECT Get_Status_Descriptiontest(a, '1', '2'), *
FROM cte;
Gives the error
SQL compliation error: Unsupported subquery type cannot be evaluated
This is the example function:
create or replace function Get_Status_Descriptiontest(Status_Code1 varchar, Status_Code2 varchar , Status_Code3 varchar )
returns varchar
as--to get sume of workdays in a given date range
$$
WITH cte AS (
SELECT 'can' DRKY, '1' DRSY, '2' DRRT, 'output1' DRDL01
)
SELECT TRIM(DRDL01)
FROM cte
WHERE TRIM(DRKY)= TRIM(Status_Code1) and TRIM(DRSY) = TRIM(Status_Code2) AND TRIM(DRRT) = TRIM(Status_Code3)
$$
;
with the real function looking like:
create or replace function Get_Status_Description(Status_Code1 varchar, Status_Code2 varchar , Status_Code3 varchar ,brand varchar)
returns varchar as
$$
SELECT TRIM(DRDL01)
FROM DB.Schema.F0005
WHERE TRIM(DRKY)= TRIM(Status_Code1) and TRIM(DRSY) = TRIM(Status_Code2)
AND TRIM(DRRT) = TRIM(Status_Code3) AND brand='TPH'
$$;