title: Multiple inserts and selects in one stored procedure
body: <p>I want to create a procedure that will</p>
  
  <p>A) check to see if TicketNumberInput is in table Tix_number.TicketNumber.</p>
  
  <p>B) if it does exisist, update the record to set UID to @uid and Set the Claimdate to GetDate()</p>
  
  <p>AND ...</p>
  
  <p>C)  INSERT A RECORD INTO ANOTHER TABLE (TRANSACTION LOG TABLE)</p>
  
  <p>If the record does exist, simply add a record to the transaction log with STATUS = 2 (failed).</p>
  
  <p>This is my code so far, but it doesn't seem to have a problem checking the IF statements AND updating the record AND inserting another record.  How do I add many checks into a statement. The Begin End didn't seem to work</p>
  
  <pre><code>create procedure [dbo].[UpdateTicketNumber]
  @TicketNumberInput uniqueidentifier, 
  @UID   int
  as 
  IF EXISTS(
  BEGIN
      SELECT *
      FROM [tixtowin].[dbo].[Tix_Number]
      where @TicketNumberInput = Tix_Number.TicketNumber)
      PRINT 'CORRECT RECORD'
  
      Update Tix_Number 
      Set Tix_Number.UID = @uid, ClaimDate = GETDATE()
      where TicketNumber = @TicketNumberInput
  
      /* Success - insert transaction message. Status = 1 */
      INSERT INTO [Tix_Transaction]
      ([Tix_Number],[UID], [status], [Datetime])
      VALUES
      (@TicketNumberInput, @UID, '1', GetDate())
  
      End
      ELSE
  
      /* Failed - insert transaction message. Status = 2 */
      INSERT INTO [Tix_Transaction]
      ([Tix_Number],[UID], [status], [Datetime])
      VALUES
      (@TicketNumberInput, @UID, '2', GetDate())
  
      PRINT 'INCORRECT RECORD'
  </code></pre>
  
  <p>THANK YOU for your help!!!</p>