I am on a journey to learn SnowFlake, but now I am really stuck on something. I have looked everywhere, and tried all solutions. But I still do something wrong.
I have:
- a Database: TRAININGDATABASE
- a Schema: Sales
- a Table: Employee
- Columns: EMPLOYEEID NUMBER(38,0),
EMPNAME VARCHAR(16777216),
JOININGDATE DATE,
LOCATION VARCHAR(16777216),
SALARY NUMBER(38,0)
Is there anyone that can help me get on with my journey? I am really stuck 🙁
What I need:
- a Function called: f_getDaysEmployed
- This Function should show me the columns:EmployeeID,
EmpName,
DATEDIFF(DAY, JOININGDATE, CURRENT_DATE) AS DaysEmployed
These 2 have given me the least issues so far.
CREATE OR REPLACE FUNCTION f_getDaysEmployed()
RETURNs TABLE (EmployeeID INT, EmpName STRING, DaysEmployed INT)
AS
$$
SELECT
EmployeeID,
EmpName,
DATEDIFF(DAY, JOININGDATE, CURRENT_DATE) AS DaysEmployed
FROM
Employee;
$$;
CREATE FUNCTION f_getDaysEmployed (DAY, JOININGDATE, CURRENT_DATE)
RETURNS TABLE
language sql
AS
$$
EmployeeID,
EmpName,
DATEDIFF(DAY, JOININGDATE, CURRENT_DATE) AS DaysEmployed;
end
$$;
FROM Employee
I have tried so many combinations now, but it always keeps giving an Syntax error on SELECT, or AS, or RETURN and so on.
New contributor
SnowY is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.