我正在使用具有表值函数的另一个视图内连接(ed)创建视图,
这个表值函数调用一个Scalar值函数来填充它的一个列,当我执行相同的时,
我收到错误说明:Maximum stored procedure, function, trigger, or view nesting level exceeded(limit 32)
任何人都可以帮助..... plz
*下面是表值函数
ALTER FUNCTION [dbo].[sstfnAllSubjectWithAASDID]
(
)
RETURNS
@tt TABLE
(
AASDID numeric(18,0),
SubjectString nvarchar(MAX),
SubjectCount int
)
AS
BEGIN
declare @pID numeric(18,0)
declare @pStr nvarchar(MAx)
declare @pCount int
Declare LAASDID Cursor Read_Only Fast_Forward for (SELECT AASDid from vwAcdAdmissionSessionDetailWithAcdAdmissionSessionSubjectDetail)
open LAASDID
FETCH next from LAASDID into @pID
while(@@FETCH_STATUS =0)
BEGIN
set @pCount = (SELECT COUNT( MasterSubject.SubjectName ) as cnt
FROM AcdAdmissionSessionSubjectDetail INNER JOIN
MasterSubject ON AcdAdmissionSessionSubjectDetail.SubjectId = MasterSubject.SubjectId where
AcdAdmissionSessionSubjectDetail.AASDID = @pID
)
set @pStr = (SELECT [dbo].[ssspfnGetSubjectname] (@pID))
Insert Into @tt (AASDID,SubjectString,SubjectCount) values (@pID,@pStr,@pCount)
FETCH next from LAASDID into @pID
END
RETURN
END
这是它所称的标量值函数
ALTER FUNCTION [dbo].[ssspfnGetSubjectname]
(
@pAASDID numeric(18,0)
)
RETURNS nvarchar(max)
AS
BEGIN
DECLARE @Cols1 as nvarchar(max)
set @Cols1 = STUFF( (SELECT DISTINCT SubjectName + ','
FROM ( SELECT AcdAdmissionSessionSubjectDetail.AASDID, MasterSubject.SubjectName as SubjectName
FROM AcdAdmissionSessionSubjectDetail INNER JOIN
MasterSubject ON AcdAdmissionSessionSubjectDetail.SubjectId = MasterSubject.SubjectId where
AcdAdmissionSessionSubjectDetail.AASDID = @pAASDID
) as ss
FOR XML PATH('')) ,1,1,'')
RETURN @Cols1
END
答案 0 :(得分:0)
试试此代码
SP_CONFIGURE 'nested_triggers',0
GO
RECONFIGURE
GO