【问题标题】:SQL Server stored procedure with parameters带参数的 SQL Server 存储过程
【发布时间】:2013-06-10 03:43:13
【问题描述】:

我是 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

【问题讨论】:

  • 去掉@SentFax int = 0后面的逗号和下一行的`=`(AS之前)。
  • @ChrisShaffer 你最好的,谢谢!把它放在一个答案中,这样我就可以给你功劳了

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


【解决方案1】:

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

以下应该按预期工作:

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

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

【讨论】:

    【解决方案2】:

    试试下面

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 2019-01-26
      • 2018-12-11
      相关资源
      最近更新 更多