I have written below SQL Server Scalar-Valued function to get the data of the specified column in the specified table. I'm passing the table name and its column name to the function. but according to this systax I can't give the @table parameter to the function and it asks me to declare it. This could be due to wrong syntax I have used here. Can anyone help me to figure it out?
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