sql-server – 超出最大存储过程,功能,触发或视图嵌套级别(限制32)

前端之家收集整理的这篇文章主要介绍了sql-server – 超出最大存储过程,功能,触发或视图嵌套级别(限制32)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建一个存储过程,但是在执行该过程时,我得到了特定的错误.

消息217,级别16,状态1,过程SendMail_Renewapp,第77行
超过最大存储过程,功能,触发或视图嵌套级别(限制32).

任何人都可以帮助我解决这个问题.

我的程序如下

  1. `ALTER PROCEDURE [dbo].[SendMail_Renewapp]
  2. -- Add the parameters for the stored procedure here
  3.  
  4. AS
  5. BEGIN
  6. declare @xml nvarchar(max)
  7. declare @body nvarchar(max)
  8. declare @currentdate datetime;
  9. declare @ExpDate datetime;
  10. declare @mailsendingdate datetime;
  11. declare @renewtime varchar(10);
  12. DECLARE @AgencyId int;
  13. DECLARE @ApplicationID int;
  14. declare @emailid varchar(100);
  15.  
  16. set @currentdate=getdate();
  17.  
  18.  
  19. --Fetching the application details: start--
  20. DECLARE AppCursor CURSOR FOR
  21. Select top 5 applications.ap_id,applications.ap_expiry_date,agency.ag_co_email from applications join agency on applications.ap_agency_id=agency.ag_id
  22. where ap_status='AS' and ap_iame_flag='IA' and ap_expiry_date != ''
  23. OPEN AppCursor
  24. FETCH NEXT FROM AppCursor INTO @ApplicationID,@ExpDate,@emailid
  25.  
  26. WHILE @@FETCH_STATUS = 0
  27. BEGIN
  28.  
  29. SET @renewtime = ABS(DATEDIFF(day,@currentdate,@ExpDate))
  30. if(@renewtime=180)
  31.  
  32. BEGIN
  33.  
  34. --SET @xml = CAST(( SELECT [ag_id] AS 'td','',[ag_name] AS 'td',[ag_co_email] AS 'td',[ag_mobile] AS 'td'FROM beesl.dbo.Agency where @renewtime < 180
  35. --FOR XML PATH('tr'),ELEMENTS ) AS NVARCHAR(MAX))
  36.  
  37. SET @body ='<html>
  38. <body>
  39. <div>
  40. <div>
  41. <H3>Agencies Details whose payment are still pending for last 3 months</H3>
  42. </div>
  43. <table cellpadding="4" cellspacing="1" bgcolor=#FFFFFF border=1 rules=none frame=Box >
  44. <tr >
  45. <th style=border:1px solid #000000; align=left bgcolor=#c2c2c2> Agency ID </th>
  46. <th style=border:1px solid #000000; align=left bgcolor=#c2c2c2> Agency Name </th>
  47. <th style=border:1px solid #000000; align=left bgcolor=#c2c2c2> Agency Email </th>
  48. <th style=border:1px solid #000000; align=left bgcolor=#c2c2c2> Contact Number </th>
  49.  
  50. </tr>'
  51. SET @body = @body + @xml +'</table></div></body></html>'
  52.  
  53. EXEC msdb.dbo.sp_send_dbmail
  54. @profile_name='BEE',@recipients='emailid@emailid.com',@subject='Renew Applications',--@file_attachments = 'D:\beelogo.png',@importance= High,--@body = 'Testing'
  55. @body = @body,@body_format ='HTML';
  56.  
  57. END
  58.  
  59.  
  60. FETCH NEXT FROM AppCursor INTO @ApplicationID,@emailid
  61. END
  62. CLOSE AppCursor
  63. DEALLOCATE AppCursor
  64. --Fetching the application details: end--
  65.  
  66.  
  67. END`

解决方法

使用 “走” 之后 结束 声明

猜你在找的MsSQL相关文章