2017-02-02 1 views
1

Pour la procédure stockée suivante, je reçois une erreursyntaxe incorrecte près de « fin »

syntaxe incorrecte près de « fin »

Au meilleur de ma connaissance, j'ai le droit de commencer et à la fin Mots clés. Je ne suis pas sûr où l'erreur est. J'ai également vérifié les questions précédentes mais je n'ai pas pu corriger l'erreur. Merci pour toute aide!

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 
+4

il manque une 'end' pour le bloc principal. –

+0

C'était juste devant mes yeux et j'ai raté .. !! Je vous remercie. –

Répondre

3

Vous avez besoin une autre end avant go.

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 [email protected]_DuplexYN, 
      DateRecChanged = getdate(), 
      UserName = @UserName 
     WHERE 
      UserName = @UserName and 
      ComputerName = @ComputerName; 
    end 
end --<-- add this 
GO 
+0

C'était juste devant mes yeux et j'ai raté .. !! Je vous remercie. –

+0

@ananthreddy Heureux de vous aider! – SqlZim