3

我有这个 SQL 语句

INSERT housingSurvey ([nameID], [houseID], [jobID], [Active], [comment], [needsMaintenance], [lastUpdateDate) 
VALUES (@NAMEID, @HOUSEID, @JOBID, 1, @DUEDATE, @COMMENT, NULL, @LASTUPDATEDATE)

我试过这个存储过程,但我没有得到当前日期。

CREATE PROCEDURE housingSurveyS(
                    @NAMEID INT,
                    @HOUSEID INT,
                    @JOBID INT, 
                    @COMMENT BIT,
                    @DUEDATE NVARCHAR,
                    CURRENTTIME)
AS
BEGIN
INSERT INTO housingSurvey(
    [nameID],
    [houseID],
    [jobID],
    [Active],
    [comment],
    [dueDate],
    [needsMaintenance],
    [lastupdatedate])
VALUES (
    @NAMEID,
    @HOUSEID,
    @JOBID,
    1,
    @COMMENT,
    @DUEDATE,
    NULL,
    @LASTUPDATEDATE)
END

请你看看我做错了什么。谢谢

更新 我将它 CURRENTTIME 更改为 DATETIME 作为参数以将当前日期插入 [lastupdatedate] ...它仍然无法正常工作...

4

1 回答 1

5
VALUES (
    ...
    @DUEDATE,
    @COMMENT 

当与 s 语句字段列表中定义的字段顺序相关时,顺序错误INSERT,请切换它们。

编辑

CREATE PROCEDURE housingSurveyS(
    @NAMEID INT,
    @HOUSEID INT,
    @JOBID INT, 
    @COMMENT BIT,
    @DUEDATE NVARCHAR(32) --add a size, should this be DATETIME
)
AS
BEGIN
INSERT INTO housingSurvey(
    [nameID],
    [houseID],
    [jobID],
    [Active],
    [comment],
    [dueDate],
    [needsMaintenance],
    [lastupdatedate]
) VALUES (
    @NAMEID,
    @HOUSEID,
    @JOBID,
    1,
    @COMMENT,
    @DUEDATE,
    NULL,
    GETDATE()
)
END
于 2012-09-28T14:27:44.173 回答