对于以下存储过程,我收到错误
'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
答案 0 :(得分:4)
end
之前需要另一个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 =@Print_DuplexYN,
DateRecChanged = getdate(),
UserName = @UserName
WHERE
UserName = @UserName and
ComputerName = @ComputerName;
end
end --<-- add this
GO