带参数的SQL Server存储过程

时间:2013-06-09 19:04:01

标签: sql sql-server-2008 stored-procedures

我是SQL Server的新手,并尝试编写一个存储过程,用于在调用存储过程时使用当前日期/时间更新记录集。我的代码会在=附近报告错误。参数@SentFax是需要更新的记录的PK,任何想法为什么不起作用?

CREATE PROCEDURE FaxMailerSent 
-- Add the parameters for the stored procedure here
@SentFax int = 0, 
  = 
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
UPDATE FaxMailer 
    SET Done = GetDate()
        WHERE [Fax_ID] = @SentFax; 
END
GO

2 个答案:

答案 0 :(得分:1)

删除,之后的@SentFax int = 0=@SentFax int = 0之间的AS

以下内容应按预期工作:

CREATE PROCEDURE FaxMailerSent 
    @SentFax int = 0
AS
BEGIN
SET NOCOUNT ON;

UPDATE FaxMailer 
    SET Done = GetDate()
        WHERE [Fax_ID] = @SentFax; 
END
GO

答案 1 :(得分:0)

尝试以下

CREATE PROCEDURE FaxMailerSent 
-- Add the parameters for the stored procedure here
@SentFax int = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
UPDATE FaxMailer 
    SET Done = GetDate()
        WHERE [Fax_ID] = @SentFax; 
END
GO
相关问题