简体   繁体   中英

SQL Server stored procedure with parameters

I'm brand new to SQL Server and trying to write a stored procedure that updates a recordset with the current date/time at the time the stored procedure is called. My code keeps reporting an error near the = . The parameter @SentFax is the PK of the record needing to be updated, any ideas why this doesn't work?

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

Remove the , after @SentFax int = 0 and the = between @SentFax int = 0 and AS .

The following should work as expected:

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

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

Try below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM