title: SQL procedure executes first line then stops
body: <p>I am running an SQL procedure that has to update a certain table. When I run the procedure it says successfully completed, yet the records are not updated when I try to debug it, it run only the line <code>SET ANSI ON</code>, then it gives the successful message. I am using SQL server 2012</p>
  
  <p>Am I missing something, is there anything I need to add? See my code here:</p>
  
  <pre><code>USE [CADDe_ProdCopy]
  GO
  /****** Object:  StoredProcedure [dbo].[sp_sms_X203]    Script Date: 2015/09/03 08:28:15 AM ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  
  
  
  ALTER        procedure [dbo].[sp_sms_X203]
  as
      declare @lCount int
      set @lCount = (select count(*) from tbl_X203_SMS where SMSSent = 0 )
      if @lCount &gt; 0 
          begin
          DECLARE @cSMSeMail varchar(100)
          declare @cSMSType varchar(10)
          declare @cSMSSent int
          declare @cRA varchar(10)
          declare @cWizard varchar(7)
          declare @cCName varchar(26)
          declare @cContact varchar(30)
          declare @cUsed_KM int
          declare @cAmount_Due decimal(18, 2)
          declare @cSMSMessage varchar(160)
          declare @cvblf varchar(1)
          declare @cCheckInDt datetime
          declare @cCheckOutDt datetime
          declare @err int
  
  
      set @cvblf = '|'
      declare lcursor CURSOR FOR 
          Select SMSType, RA, CName, Contact, Used_KM, Amount_Due, eMail, [CheckInDateTime] ,[CheckOutDateTime] 
          From tbl_X203_SMS WHERE SMSSent = 0
      open lcursor
      fetch next from lcursor into @cSMSType, @cRA, @cCName, @cContact, @cUsed_KM, @cAmount_Due, @cSMSeMail, @cCheckInDt, @cCheckOutDt
      while @@FETCH_STATUS = 0
          begin
          --SET @cContact = '+27834115771'
          --SET @cSMSeMail = 'amangelsdorf@avis.co.za'
  
  
  -- Check that the date of the checkin is within same day
              if rtrim(ltrim(@cSMSType)) = 'CheckIn'
                  begin               
                      if datediff(day,@cCheckInDt,getdate()) = 0
                      begin
                          SET @cSMSMessage = left('Thank you '+ @cCName +' for renting with AVIS.',160)
                          SET @cSMSMessage = left( @cSMSMessage + ' RA#' + @cRA + 'Retrieve your invoice at http://www.avis.co.za/inv' ,160)
                          --if @cAmount_Due &gt; 0
                          --  SET @cSMSMessage = left( @cSMSMessage + @cvbLf + 'AMT:R ' + cast(@cAmount_Due as varchar),160)
                          exec sp_sms_xml_post @cContact, @cSMSMessage, @cSMSeMail
                      end
                  end
  
  
      -- Check that the date of the checkout is within same day
              if rtrim(ltrim(@cSMSType)) = 'CheckOut'
                  begin
                  if datediff(day,@cCheckOutDt,getdate()) = 0
                      begin
                          --SET @cSMSMessage = left( 'Thank you for choosing AVIS.' + @cvbLf + 'For any  assistance contact the AVIS Careline on Tel: 0800001669' ,160)
                          SET @cSMSMessage = left( 'Thank you for choosing AVIS. ' + @cvbLf + 'Kindly contact 0800001669 for any roadside or emergency assistance.' ,160)
                          exec sp_sms_xml_post @cContact, @cSMSMessage, @cSMSeMail
                      end
                  end
  
              set @err = @@error
              if @err = 0
                  begin
                      --print 'no error'  
                      update tbl_X203_SMS set SMSSent = 1 where SMSType = @cSMSType and RA = @cRA                     
                  end
              fetch next from lcursor into @cSMSType, @cRA, @cCName, @cContact, @cUsed_KM, @cAmount_Due, @cSMSeMail, @cCheckInDt, @cCheckOutDt
          end
  
      close lcursor
      deallocate lcursor
  end
  </code></pre>
  
  <p>`</p>