Using SQL Server 2014...
I'm trying to convert this code to be used in a function...
SET @sqlCommand = N'SELECT @text = ' + @fieldname + ' FROM ' + @tablename +' WHERE ID=''' + CONVERT(NVARCHAR(200), @ID) + ''''
EXECUTE sp_executesql...
...but functions doesn't accept sp_executesql.
How can I in a function get data from a table where the tablename
is coming from a parameter?