Using Extended stored proc's within functions / dynamic SQL
-
Hello... I'm using T-SQL. What I'm trying to do is (within a function) read a value from a specified dynamic column, and return that value for usage elsewhere. The following lines would do the trick: [code] SET @SqlString = 'SELECT @Value = [' +@ColumnName +'] FROM SettingTable WHERE ID = 50' exec sp_executeSql @SqlString,N'@Value int OUTPUT', @Value OUTPUT [/code] However, I can't use that within a function (Only functions and extended stored procedures can be executed from within a function), even though sp_help tells me that sp_executeSql is an extended stored procedure. Is there some way I should be calling the executesql proc that would allow it? Or is there another way I should be generating my dynamic query that would be allowed within a function, and which will allow me to get an output value from the query?