Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

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

Avatar of devilJinKazama
devilJinKazama
Flag of Australia image

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?
Avatar of lapucca
lapucca

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of devilJinKazama
devilJinKazama
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
reason : the 'BEGIN' command needs the 'END' command at the bottom.
Avatar of lapucca

ASKER

Ah, I see.  Thank you.