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 ')'.
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))
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
reason : the 'BEGIN' command needs the 'END' command at the bottom.
ASKER
Ah, I see. Thank you.
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?