我是新来的sql编程;试图开发这一功能让谁拥有从视图访问的特定客户数量行:SQL Server 2008 - 函数错误
ALTER FUNCTION [dbo].[fn_NumberOfVisit]
(
@nv int
)
RETURNS varchar(500)
AS
BEGIN
DECLARE @ret varchar(500)
select *
from (
select
*,
rn = row_number() over (partition by ClientId order by VisitId)
from
Visit
) activityWithRn
inner join vw_MasterView on vw_MasterView.VisitId = activityWithRn.VisitId
where activityWithRn.rn [email protected]
RETURN @ret
END
我得到以下错误:
Select statements included within a function cannot return data to a client
我会感谢您的支持。提前致谢。
你有一个错字 –
而不是'设置@var =(select'你可能使用'选择@var = ...'。 –
@NikolaMarkovinović,这不会帮助。子查询使用SELECT *这将是多个列,也不能分配给一个变量 - 即使它只是一列,它仍然是一些任意的行从多行结果来看,太多的其他问题也需要在评论中列出来 –