调用存储过程时出现语法错误。

时间:2016-07-08 10:24:21

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

存储过程

create procedure insertUser
    @uname varchar(50),@udob date, @uadd varchar(100),@umob bigint
as
begin
    insert into userInfo values(@uname,@udob,@uadd,@umob)
end
go

insertUser 'Samuel' '1990-14-04' 'Shivajinagar Pune' 12345630

错误消息:

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '1990-04-14'.

2 个答案:

答案 0 :(得分:0)

您对SP的呼叫不正确。将参数与,分开,如下所示。此外,日期应以标准格式输入(mm-dd-yyyy或yyyy-mm-dd)

insertUser 'Samuel', '1990-04-14', 'Shivajinagar Pune', 12345630

答案 1 :(得分:0)

在调用存储过程时传递参数name = value会很清楚。

这样打电话,

CREATE PROCEDURE insertUser @uname VARCHAR(50)
    ,@udob DATE
    ,@uadd VARCHAR(100)
    ,@umob BIGINT
AS
BEGIN
    INSERT INTO userInfo
    VALUES (
        @uname
        ,@udob
        ,@uadd
        ,@umob
        )
END
GO

EXEC insertUser @uname = 'Samuel'
    ,@udob = '1990-14-04'
    ,@uadd = 'Shivajinagar Pune'
    ,@umob = 12345630