Why I got syntax error when concatenate strings?

Here is the error msg I got, which indicates the last line in the code blow
Msg 102, Level 15, State 1, Procedure usp_InsertNewDoctor, Line 21
Incorrect syntax near ')'.
INSERT INTO [Doctors]
           ([LastName]
           ,[FirstName]
           ,[FullName])
     VALUES
           (@FirstName
           ,@LastName
           ,(@LastName + ', ' + @FirstName))

Open in new window

lapuccaAsked:
Who is Participating?
 
devilJinKazamaCommented:
ah ok, try this

CREATE PROCEDURE usp_InsertNewDoctor(@FirstName nchar(30), @LastName nchar(30))
AS

      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

    -- Insert statements for procedure here
INSERT INTO [AdaptSurvey].[dbo].[Doctors]
           ([LastName]
           ,[FirstName]
           ,[FullName])
     VALUES
           (@FirstName
           ,@LastName
           ,(@LastName + ', ' + @FirstName))
GO
0
 
devilJinKazamaCommented:
there is nothing wrong with your SQL syntax.

it could be that the value of the firstname or lastname has some special characters that breaks the SQL statement? are they properly validated before being passed into the SP?

Are you sure its this insert statement that throws the syntax error?
0
 
lapuccaAuthor Commented:
This is actually a sp that I'm creating that gives error

CREATE PROCEDURE usp_InsertNewDoctor(@FirstName nchar(30), @LastName nchar(30))
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
INSERT INTO [AdaptSurvey].[dbo].[Doctors]
           ([LastName]
           ,[FirstName]
           ,[FullName])
     VALUES
           (@FirstName
           ,@LastName
           ,(@LastName + ', ' + @FirstName))
GO

Open in new window

0
 
devilJinKazamaCommented:
reason : the 'BEGIN' command needs the 'END' command at the bottom.
0
 
lapuccaAuthor Commented:
Ah, I see.  Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.