title: Incorrect syntax near 'end'
body: <p>For the following stored procedure, I get an error </p>
  
  <blockquote>
    <p>Incorrect syntax near 'end'</p>
  </blockquote>
  
  <p>To the best of my knowledge I have the right begin and end tags. I'm not sure Where the error is. I have checked the previous questions as well but couldn't rectify the error. Thank you for any help!</p>
  
  <pre><code>USE CONTACT
  GO
  
  SET ANSI_NULLS ON
  GO  
  SET QUOTED_IDENTIFIER ON
  GO
  
  CREATE PROCEDURE [dbo].[Pref] 
      (@userName VARCHAR(50),
       @ComputerName VARCHAR(50),
       @PrinterDescription VARCHAR(255),
       @PrinterLocation VARCHAR(255),
       @Print_DuplexYN TINYINT,
       @DateRecChanged datetime
      )
  AS
  BEGIN
      DECLARE @userID INT;
  
      SELECT @userID = User_ID
      FROM tblUser
      WHERE Login_ID = @userName
  
      DECLARE @MyCount INT
  
      SELECT @MyCount = COUNT(UserName) 
      FROM PrinterPrefs 
      WHERE UserName = @UserName AND ComputerName = @ComputerName
  
      IF @MyCount = 0 
      BEGIN
          INSERT INTO PrinterPrefs (UserName, ComputerName, PrinterDescription, PrinterLocation, Print_DuplexYN, DateRecChanged)
          VALUES (@UserName, @ComputerName, @PrinterDescription, @PrinterLocation, @Print_DuplexYN, getdate(), @UserName)
      END
      ELSE
      BEGIN
          UPDATE PrinterPrefs
          SET PrinterDescription = @PrinterDescription,
              PrinterLocation = @PrinterLocation,
              Print_DuplexYN = @Print_DuplexYN,
              DateRecChanged = getdate(),
              UserName = @UserName
          WHERE
              UserName = @UserName AND
              ComputerName = @ComputerName
      END
  GO
  </code></pre>