title: SQL Server trigger on insert
body: <p>When I try to insert a new record into the table I created the trigger on it does not create.</p>
  <p>This is after I activated the trigger. When I deactivate it then repeated the insert, it goes through. What am I missing in my trigger?</p>
  <p>My trigger identifies all the new rows in a table then emails them to a recipient.</p>
  <p>This is my trigger</p>
  <pre><code>USE [paldbCAT_TEST]
  GO
  /****** Object:  Trigger [dbo].[LPO_ON_INSERT]    Script Date: 10-11-2020 12:09:01 PM ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  ALTER trigger [dbo].[LPO_ON_INSERT] 
  ON [dbo].[tblOrdersDocP_POApprovals]
  INSTEAD OF INSERT AS
  
  Declare
  @HTMLbody nvarchar (max),
  @strOrdPDocID varchar(100),
  @strSelectedApproverUserName varchar(50),
  @SQL nvarchar(max)
  
  SET @SQL =''
  
  Set @HTMLbody = '&lt;html&gt;&lt;head&gt;&lt;title&gt; System Tables&lt;/title&gt;&lt;/head&gt;&lt;body&gt;'
  Set @HTMLbody = @HTMLbody + '&lt;center&gt;       &lt;h1 style=&quot;font-family: arial, sans-serif&quot;&gt;Purchase Requisition(s) awaiting approvals.&lt;/h1&gt;&lt;/center&gt;'
  Set @HTMLbody = @HTMLbody + '&lt;center&gt;&lt;table style=&quot;font-family: arial, sans-serif;border-collapse: collapse;width: 100%;&quot; &gt;&lt;TH style=&quot;background-color:black; color:white;border: 1px solid #dddddd;text-align: left;padding: 8px;&quot;&gt;Document Number&lt;/TH&gt;&lt;TH style=&quot;background-color:black; color:white;border: 1px solid #dddddd;text-align: left;padding: 8px;&quot;&gt;Document Approver&lt;/TH&gt;'
  
  declare SystemTable cursor
  
  for
  select strOrdPDocID,strSelectedApproverUserName from tblOrdersDocP_POApprovals
  open SystemTable
  Fetch next from SystemTable into @strOrdPDocID,@strSelectedApproverUserName
  
  
  While (@@FETCH_STATUS&lt;&gt; -1)
  Begin
  Set @SQL = @SQL + '&lt;TR&gt;&lt;TD style=&quot; border: 1px solid #dddddd;text-align: left;padding: 8px;&quot;&gt;' +@strOrdPDocID + '&lt;/TD&gt;&lt;TD style=&quot; border: 1px solid #dddddd;text-align: left;padding: 8px;&quot;&gt;' + @strSelectedApproverUserName + '&lt;/TD&gt;&lt;/TR&gt;'
  
  Fetch next from SystemTable into @strOrdPDocID,@strSelectedApproverUserName
  End
  Close SystemTable
  DEALLOCATE SystemTable
  
  
  Set @HTMLbody = @HTMLbody + @SQL + '&lt;/table&gt;&lt;/center&gt;&lt;/body&gt;&lt;/html&gt;'
  
  
  
  
  EXEC msdb.dbo.sp_send_dbmail
  @profile_name = 'CatNotificationsMain',
  @recipients = 'test@gmail.com',
  @subject = 'Database Record Deleted',
  @body_format='HTML',
  @body = @HTMLbody,
  @attach_query_result_as_file = 0;
  
  
  </code></pre>