加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 接收错误“函数中包含的Select语句无法将数据返回给客户

发布时间:2020-12-12 06:29:56 所属栏目:MsSql教程 来源:网络整理
导读:尝试在函数中使用Select语句时收到错误.错误说明: Msg 444,Level 16,State 2,Procedure JDE_GetWhereClause_test,Line 26 Select statements included within a function cannot return data to a client. 有任何想法吗? CREATE FUNCTION [dbo].[JDE_GetWhe
尝试在函数中使用Select语句时收到错误.错误说明:

Msg 444,Level 16,State 2,Procedure JDE_GetWhereClause_test,Line 26
Select statements included within a function cannot return data to a client.

有任何想法吗?

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

解决方法

尝试玩像……
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,'') as blah)

  -- Return the result of the function
  RETURN @ResultVar
END

选择’答案是:'[dbo].[JDE_GetWhereClause_test](‘无论’)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读