title: How can I stop the execution of a trigger from inside itself?
body: <p>Here is the code. It is a trigger that is executed after an insert</p>
  
  <pre><code> ALTER TRIGGER [dbo].[GameStacker]
   ON [dbo].[CDKeyUser]
   AFTER INSERT AS 
   BEGIN
      INSERT INTO User_Achivement
              ( User_ID ,
              Achivement_ID,
              Date 
              )
      VALUES  ((SELECT User_ID from inserted),
              (SELECT 
                  CASE
                      WHEN COUNT(cd.User_ID)=1 THEN   1
                      WHEN COUNT(cd.User_ID)=5 THEN   2
                      WHEN COUNT(cd.User_ID)=10 THEN  3
                      WHEN COUNT(cd.User_ID)=15 THEN  4
                  END
              FROM CDKeyUser cd
              WHERE cd.User_ID=(SELECT User_ID from inserted)
              ),                  
              GETDATE()
              )
   END
  </code></pre>
  
  <p>So my problem is that this trigger executes after every insert.( I know that is how it is supposed to work. ) But, if WHEN COUNT(cd.User_ID) has a value other than the values specified here, it should not execute,or just break the execution. If I add an else statement after <code>WHEN COUNT(cd.User_ID)=15 THEN 4</code> I can't include any code there like raiseerror because it is translated into the value of Achivement_ID and it gives me an error. 
  So basically i have to break the execution of the insert statement.</p>
  
  <p>I would really appreciate if someone could help me out with this</p>