Reception error "Selective statements included in the function cannot return data to the client"

Getting an error while trying to use the Select statement in a function. Error:

Msg 444, Level 16, State 2, Procedure JDE_GetWhereClause_test, Line 26
The select statements included in the function cannot return data to the client.

Any ideas?

CREATE FUNCTION [dbo].[JDE_GetWhereClause_test] ( @tablename as varchar ) RETURNS varchar(max) AS BEGIN -- Declare the return variable here Declare @ResultVar as varchar(max) -- Add the T-SQL statements to compute the return value here set @tablename = 'F0101' Declare @Sql nvarchar(max) Declare my_cur cursor for SELECT fsuser FROM dbo.JDE_ExRowSecurity where fsuser = fsuser; Declare @fsuser as nchar(15) open my_cur; fetch next from my_cur; while @@fetch_status = 0 begin fetch next from my_cur into @fsuser; set @ResultVar += ',' + @fsuser; end; close my_cur; deallocate my_cur; -- Return the result of the function RETURN @ResultVar END 
+6
source share
1 answer

Try playing with something like ...

 CREATE FUNCTION [dbo].[JDE_GetWhereClause_test] ( @tablename as varchar ) RETURNS varchar(max) AS BEGIN -- Declare the return variable here Declare @ResultVar as varchar(max) -- Add the T-SQL statements to compute the return value here set @ResultVar = (select STUFF((SELECT ',', fsuser as [text()] FROM dbo.JDE_ExRowSecurity FOR XML PATH ('')), 1, 1, '') as blah) -- Return the result of the function RETURN @ResultVar END 

select 'Answer is: '+[dbo].[JDE_GetWhereClause_test]('whatever')

+9
source

All Articles