Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert stored procedure passing parameter

I have this SQL statement

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

I tried this stored procedure, but I don't get the current date.

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

Could you please take a look at what I did wrong. Thanks

UPDATE I changed it CURRENTTIME to DATETIME as parameter to insert current date to [lastupdatedate]... it still doesn't work...

like image 636
EagleFox Avatar asked Oct 21 '25 12:10

EagleFox


1 Answers

VALUES (
    ...
    @DUEDATE,
    @COMMENT 

Are in the wrong order when related to the order of fields defined in the INSERTs statements field list, switch them around.

Edit

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
like image 75
Alex K. Avatar answered Oct 24 '25 05:10

Alex K.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!