'end'附近的语法不正确



对于以下存储过程,我收到错误

"结束"附近的语法不正确

据我所知,我有正确的开始和结束标签。我不确定错误在哪里。我也检查了之前的问题,但无法纠正错误。感谢您的任何帮助!

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

go之前,您需要另一个end

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
end --<-- add this
GO

相关内容

最新更新