title: Trigger causes insert to fail
body: <p>i create a trigger in MSSQL on a table of web application. The problem is that after I created this trigger I get an error when I try to submit a form.
  Web application works as a social network and sends messages. I want to send this messegaes by SMS to recipients of this messages. So mz trigger makes insert of text and number of recipients in SMSServer.
  Can you pls help me to fix it?</p>
  
  <p>Here is my trigger:</p>
  
  <pre><code>create trigger trigger_ZpravyMonoxViaSMS on [dbo].[SnMessageRecipient] 
  after insert  as
  SET NOCOUNT ON;
  DECLARE @text as nvarchar(160)
  DECLARE @calledstatio nvarchar(20)
  DECLARE @id uniqueidentifier
  DECLARE @ms int
  SET @id = (select top 1 i.messageid from inserted i)
  SET @text = (select left(Body,160) 
               from SnMessage s 
               join SnMessageRecipient sr on s.id = sr.MessageId 
               where s.id = @id)
  SET @calledstatio = (select '420'+tolist 
                       from SnMessage s 
                       join SnMessageRecipient sr on s.id = sr.MessageId
                       where s.id = @id)
  SET @ms = (select i.messagestatus from inserted i where i.MessageId = @id)
  if @ms like '1'
  begin
  insert into [SQL].[SMSServer].[dbo].[MessageOut]( messageto
                ,messagefrom
                ,messagetext
                ,messageType
                ,gateway
                ,userid
                ,isread
                ,issent)
  values (@calledstatio, '', @text, '', 'GSM', '1', '0','0')
  end
  </code></pre>