There is an answer on ASP.NET forums that seems to imply it's possible to get around the 'no stored procedures in functions' rule without using OPENROWSET. The code from the link is below:
create function demofunc(@input varchar(200))
returns table
as
begin
declare @string1 varchar(100);
declare @finalstring as varchar(100);
set @string1 = '%';
set @finalstring = @input + @string1;
declare @table as table (define your table here)
insert into @table
EXEC sp_FindStringKeyInTable '', 'dbo', 'resultCustKeywordSearchView'
select * from @table
return
end
I get this error when I try to use it:
Invalid use of a side-effecting operator 'INSERT EXEC' within a function.
This is my code:
CREATE FUNCTION dbo.crds_GetFormAnswer
(@FieldName varchar(max),
@TableName varchar(max),
@PrimaryKeyColumnName varchar(max),
@DataRecordId int)
RETURNS varchar(max)
AS
BEGIN
DECLARE @temp_table AS TABLE (Form_Answers varchar(max))
INSERT INTO @temp_table (Form_Answers)
--VALUES ( '12345' ) //This code works
EXEC crds_sp_GetFormAnswer @FieldName = 'Submission_Data', @TableName = 'cr_Submissions',@PrimaryKeyColumnName = 'Submission_ID', @DataRecordId = 15;
RETURN (select TOP 1 Form_Answers from @temp_table)
END
GO
SELECT [dbo].crds_GetFormAnswer('Submission_Data', 'cr_Submissions', 'Submission_ID', 15)