title: How to stop a Transaction in SQL Server 2008?
body: <p>How to stop a transaction if an if condition fails?</p>
  
  <p>I want this transaction to stop if <code>IF (@dela = '01-01-2013')</code> is true, but instead it raises the error and procedes with the <code>Update</code> execution.</p>
  
  <pre><code>CREATE TRIGGER TR_AdaugareModificareOfertaSpeciala
  ON OferteSpeciale
  FOR UPDATE, INSERT
  AS
  BEGIN TRAN T1;
  DECLARE @dela DATETIME;
  SET @dela = (SELECT dela FROM INSERTED);
  
  IF (UPDATE(codP) OR UPDATE(codM) OR UPDATE(dela))
  BEGIN
  RAISERROR('Nu se poate modifica cheia primara.', 1, 1);
  ROLLBACK TRAN T1;
  END
  
  SAVE TRANSACTION T1;
  IF (@dela = '01-01-2013')
  BEGIN
  RAISERROR('Data nu este corecta.', 1, 1);
  ROLLBACK TRAN T1;
  END
  </code></pre>
  
  <p>Example where <code>dela = '01-01-2013':</code></p>
  
  <pre><code>UPDATE OferteSpeciale SET pret = 23.69 where codP = 'P1' and codM = 'M1'; 
  </code></pre>
  
  <p>It raises the error but also makes the update.</p>
  
  <p>Thank you.</p>