sql - 收到以下错误“函数中包含的选择语句无法将数据返回给客户端”
问题描述
我正在尝试创建以下功能:
Create function mastercount
(
@table nvarchar(50)
, @policy nvarchar(20)
, @firstname nvarchar(20)
, @lastname nvarchar (20)
)
Returns nvarchar (50)
As
Begin
Declare @count int =''
If @table ='A'
Select count (*)
from A
where policy = @policy and firstname = @firstname and lastname = @lastname
Else If @table ='B'
Select count (*)
from A
where policy = @policy and firstname = @firstname and lastname = @lastname
Else If @table ='A'
Select count (*)
from A
where policy = @policy and firstname = @firstname and lastname = @lastname
Return @count;
End
但我收到一个错误:
函数中包含的 SELECT 语句无法将数据返回给客户端
解决方案
你可以这样试试。变量@count 被分配了一个空字符串。我将其更改为默认值为 0。此外,SELECT 语句试图将记录返回给客户端。现在它们都被分配给变量@count。
Create function mastercount
(
@table nvarchar(50)
, @policy nvarchar(20)
, @firstname nvarchar(20)
, @lastname nvarchar (20)
)
Returns int
As
Begin
Declare @count int=0;
If @table ='A'
Select @count=count(*)
from A
where policy = @policy and firstname = @firstname and lastname = @lastname
Else If @table ='B'
Select @count=count(*)
from A
where policy = @policy and firstname = @firstname and lastname = @lastname
Else If @table ='A'
Select @count=count(*)
from A
where policy = @policy and firstname = @firstname and lastname = @lastname
Return @count;
End
推荐阅读
- javascript - 如何使用 javascript 在 DDB 中插入嵌套地图
- javascript - 如何在 json JS 中抓取最深的嵌套对象
- javascript - 谷歌 appscript onChange 触发器,设置时间戳
- discord - DIScord斜线命令交互在discord py上失败
- node.js - 节点 HTTPS - 在 API 端点上做了一个 get 并且它工作了,现在它是一个 404
- python - 用于读取 Sentinel XML 元数据文件的 Python 脚本
- javascript - Node/Express 向主函数返回错误?
- go - Go - 检查 Firestore 文档是否存在
- javascript - 在 docker 容器中运行多个不同的 node.js 实例
- javascript - peerjs - 在不破坏对等连接的情况下关闭与特定对等 ID 的连接