[Solved] SQL Server Insert Into Error: Incorrect syntax near concat

lingers
 
on Mar 05, 2021 10:25 PM
612 Views

i was trying to add a string to a column value but i got this error .Msg 102, Level 15, State 1, Line 16. Incorrect syntax near 'concat'.

Please help

INSERT INTO Customers concat   (CustomerName +' '+ 'copy') as CustomerName,CustomerEmail,CustomerCity,Dater,Datea,quantity,regno,Age,Height)
SELECT CustomerName,CustomerEmail,CustomerCity,Dater,Datea,quantity,regno,Age,Height
FROM Customers  WHERE  id ='1'

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Mar 06, 2021 12:25 AM
on Mar 06, 2021 05:57 AM

Hi lingers,

Replace with below query.

INSERT INTO Customers (CustomerName,CustomerEmail,CustomerCity,Dater,Datea,quantity,regno,Age,Height)
SELECT (CustomerName +' '+ 'copy'),CustomerEmail,CustomerCity,Dater,Datea,quantity,regno,Age,Height
FROM Customers WHERE id ='1'

Check this example.

Database

I have made use of the following table Customers with the schema as follows.

I have already inserted few records in the table.

You can download the database table SQL by clicking the download link below.

Download SQL file

SQL

INSERT INTO Customers (Name,Country)
SELECT Name +' '+ 'copy',Country
FROM Customers WHERE  CustomerId ='1'
SELECT * FROM Customers

Output

CustomerId Name Country
1 John Hammond United States
2 Mudassar Khan India
3 Suzanne Mathews France
4 Robert Schidner Russia
5 John Hammond copy United States