存储过程在执行时出错

时间:2015-04-02 03:34:59

标签: sql sql-server-2008

CREATE PROCEDURE  usp_InsertUserDetails
    @FirstName nvarchar(20),
    @MiddleName nvarchar(20),
    @LastName nvarchar(30),
    @FullName nvarchar(50),
    @PhoneNo nvarchar(15),
    @FaxNo nvarchar(15),
    @EmployeeId nvarchar(64),
    @EmailAddress nvarchar(256),
    @SSOID nvarchar(76),
    @IsSFDC bit,
    @IsActive bit,
    @ManagerId int,
    @LastLoginDateTime datetime,
    @CreatedBy int,
    @CreatedDate datetime,
    @UpdatedBy int,
    @UpdatedDate datetime,
    @IsDeleted bit
AS   
BEGIN
    INSERT INTO UserDetail(FirstName, MiddleName, LastName, FullName, PhoneNo, FaxNo, EmployeeId, EmailAddress, SSOID, IsSFDC, IsActive, ManagerId, LastLoginDateTime, CreatedBy, CreatedDate, UpdatedBy, UpdatedDate, IsDeleted)
    VALUES (@FirstName, @MiddleName, @LastName, @FullName, @PhoneNo, @FaxNo, @EmployeeId, @EmailAddress, @SSOID, 0, 1, 2, GETDATE(), 1, GETDATE(), 1, GETDATE(), 0)
END

执行如下:

exec usp_InsertUserDetails 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 0, 1, 1, GETDATE(), 1, GetDate(), 1, GETDATE(), 0

我收到错误:

  

Msg 102,Level 15,State 1,Line 1
  ')'附近的语法不正确。

3 个答案:

答案 0 :(得分:1)

尝试使用变量存储当前日期/时间:

declare @now datetime = getdate();

exec usp_InsertUserDetails 'test', 'test', 'test', 'test', 'test', 'test',
        'test', 'test', 'test', 0, 1, 1,
         @now, 1, @now, 1, @now, 0;

答案 1 :(得分:1)

在这种情况下,您无法使用函数调用参数getdate()调用存储过程。改为分配给变量。

答案 2 :(得分:-1)

试试这个,

DECLARE @tmp DATETIME
SET @tmp = GETDATE()
exec usp_InsertUserDetails 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 0, 1, 1,@tmp , 1, @tmp, 1, @tmp, 0