I am trying to build a Function that accepts multi-value parameters by referencing the code here. However, I am getting an error creating it. What is wrong here?
CREATE FUNCTION [dbo].[func_CommaDelimitedString] (@val nvarchar(100))
RETURNS @clublist TABLE (clubname nvarchar(55))
BEGIN
DECLARE @x int = 1
DECLARE @y int = CHARINDEX(',', @val)
WHILE @x < LEN(@val) + 1
BEGIN
IF @y = 0
BEGIN
SET @y = LEN(@val) + 1
END
INSERT INTO @clublist (clubname) VALUES (SUBSTRING(@val, @x, @y - @x))
SET @x = @y + 1
SET @y = CHARINDEX(',', @val, @x)
END
RETURN
END
Msg 103010, Level 16, State 1, Line 1 Parse error at line: 13, column: 15: Incorrect syntax near '@clublist'.
My Environment: Microsoft Azure SQL Data Warehouse - 10.0.10887.0 Jan 23 2020 07:36:54 Copyright (c) Microsoft Corporation