Receiving error “Select statements included within a function cannot return data to a client”

前端 未结 2 642
深忆病人
深忆病人 2021-01-07 23:01

Receiving an error when attempting to use a Select statement in a function. The error states:

Msg 444, Level 16, State 2, Procedure JDE_GetWhereClause

相关标签:
2条回答
  • 2021-01-07 23:09

    Found this MSDN article helpful and it resolved my issue:

    RETURN (SELECT GETDATE());
    

    Returning values directly from a select statement, avoiding variable.

    0 讨论(0)
  • 2021-01-07 23:30

    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')

    0 讨论(0)
提交回复
热议问题