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

Microsoft SQL Server 2005

Avatar of undefined
Last Comment
lapucca
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of devilJinKazama
devilJinKazama
Flag of Australia image

reason : the 'BEGIN' command needs the 'END' command at the bottom.
Avatar of lapucca
lapucca

ASKER

Ah, I see.  Thank you.
Microsoft SQL Server 2005
Microsoft SQL Server 2005

Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.

72K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo