gpt4 book ai didi

sql-server - 包含在函数中的 Select 语句不能将数据返回给 client_New

转载 作者:行者123 更新时间:2023-12-02 02:47:46 24 4
gpt4 key购买 nike

我一直在阅读问题标题上的错误,但我无法弄清楚下面代码中的错误是什么:

CREATE function [RPT].[MonthlyRollupDates_Delimited]()
RETURNS @table TABLE (Value varchar(max))
AS
BEGIN

Declare @Count int , @Date date = getdate(),@Month int
SET @Month = MONTH(@Date)
SET @Count = @Month +12


Select
top (@Count)
CalendarDate, BusinessDay, Label
from MonthlyRollupDates
order by Calendardate desc

return
end
GO

我得到的错误是

Select statements included within a function cannot return data to a client

最佳答案

你需要把你的结果SELECT进入您的返回表,然后返回该表。

CREATE function [RPT].[MonthlyRollupDates_Delimited]()
--notice i modified the table to match the select statement, but assumed datatypes
RETURNS @table TABLE (CalendarDate datetime, BusinessDay int, Label char(10))
AS
BEGIN

declare @Count int
SET @Count = month(getdate()) + 12

--place your select into the table variable
insert into @table
Select top (@Count)
CalendarDate
,BusinessDay
,Label
from
MonthlyRollupDates
order by
Calendardate desc

return
end
GO

关于sql-server - 包含在函数中的 Select 语句不能将数据返回给 client_New,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53635500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com