Reputation: 5393
Hi I am trying to create a stored procedure but each time I try to save it I get an error
Msg 102, Level 15, State 1, Procedure forum_Insert_Post, Line 3
Incorrect syntax near '@description'.
Msg 137, Level 15, State 2, Procedure forum_Insert_Post, Line 9
Must declare the scalar variable "@title"
This is my code:
CREATE PROCEDURE forum_Insert_Post
@title nvarchar
@description nvarchar
@subcategoryId int
@date dateTime
@usernameId uniqueidentifier
AS
INSERT INTO forum_posts (PostTitle , PostContent , PostDate , UserId , SubcategoryId)
VALUES (@title , @description , @date , @usernameId , @subcategoryId)
What am I doing wrong here?
Upvotes: 1
Views: 106
Reputation: 107387
Just add some commas, and also give the nvarchar
s an appropriate size, else it will truncate to 1 char :)
CREATE PROCEDURE forum_Insert_Post
@title nvarchar(20),
@description nvarchar(20),
@subcategoryId int,
@date dateTime,
@usernameId uniqueidentifier
AS
INSERT INTO forum_posts (PostTitle , PostContent , PostDate , UserId , SubcategoryId)
VALUES (@title , @description , @date , @usernameId , @subcategoryId)
SQLFiddle of the NVARCHAR
truncation here
Upvotes: 4
Reputation: 115538
You need commas after the parameters:
CREATE PROCEDURE forum_Insert_Post
@title nvarchar,
@description nvarchar,
@subcategoryId int,
@date dateTime,
@usernameId uniqueidentifier
AS
INSERT INTO forum_posts (PostTitle , PostContent ,
PostDate , UserId , SubcategoryId)
VALUES (@title , @description , @date , @usernameId , @subcategoryId)
Upvotes: 4