when I try to execute this function I get a error. When I execute the command without a function and without using variables it works, therefore I think the value does not apply to my variable, the declaration or the setting of variable does not work. It doesn't matter if I use SELECT or SET to set the variable, I get the same error which literally just says: The command could not be executed.
CREATE FUNCTION ueberpruefe_kfz_status (@kennzeichen CHAR(15))
RETURNS VARCHAR
AS
BEGIN
DECLARE @ergebnis VARCHAR
SELECT STATUS
INTO @ergebnis
FROM KFZ
WHERE KENNZEICHEN = @kennzeichen
RETURN @ergebnis
END
Here are some screenshots of the structure, sample data and the error: https://picload.org/folder/ldpwa.html