title: THROW ERROR Still Executes Query And Inserts Data Into Table
body: <p>Basically, I am trying to compare a date the user will enter and if it is greater than todays date (GETDATE()), then it throws the error and doesn't enter the data. The query throws the error but it still enters the data with the result at the bottom.</p>
  
  <pre><code>USE EMR
  GO
  
  IF EXISTS (SELECT DB_ID('CheckDate'))
      DROP TRIGGER CheckDate
      GO
  
  CREATE TRIGGER CheckDate
  ON VISIT
  AFTER INSERT, UPDATE
  AS
  BEGIN TRAN
      DECLARE @ErrorMessage VARCHAR(200)
      DECLARE @Date VARCHAR(20) = CAST ((SELECT CONVERT (DATE, GETDATE())) AS VARCHAR(20))
      SET @ErrorMessage = 'Date Must Be On Or Before ' + @Date + '';
  
      DECLARE @CheckDate DATE = (SELECT Date_Of_Service FROM inserted);
  
      IF CAST((@CheckDate) AS DATE) &lt;= CAST(GETDATE() AS DATE)
          COMMIT TRAN
  
      ELSE
          RAISERROR(@ErrorMessage, 1, 1)
  </code></pre>
  
  <p>This is my insert statement:</p>
  
  <pre><code>INSERT INTO VISIT (PK_VISIT_ID, Date_Of_Service)
  VALUES (02913, '2018-12-03')
  </code></pre>
  
  <p>And get this:</p>
  
  <pre><code>Date Must Be On Or Before 2016-02-17
  Msg 50000, Level 1, State 1
  
  (1 row(s) affected)
  </code></pre>