我在下面写了 SQL Server Scalar-Valued 函数来获取指定表中指定列的数据。我将表名及其列名传递给函数。但是根据这个系统税,我不能给函数@table参数,它要求我声明它。这可能是由于我在这里使用了错误的语法。谁能帮我弄清楚?
USE [mydatabse]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[FnTDEVgroupConcat2]
(@fieldName varchar(max),
@table varchar(max)
)
RETURNS varchar(max)
AS
BEGIN
-- Declare the return variable here
DECLARE @result varchar(max)
set @result = (SELECT @fieldName + ',' FROM @table FOR XML PATH(''));
-- Return the result of the function
RETURN @result;
END