2

I am using SQL Server 2008 R2 and am trying to run the following command:

SELECT CustCity AS City, Concat(CustLastName, \', \', CustFirstName) AS Customer
FROM Customers
ORDER BY CustCity, Customer

The error message I am receiving is:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ', \'.

As far as I have learnt, this is how Concat should work so I don't understand why this is not working.

Can anyone help?

2
  • 2
    CONCAT is a NEW function in SQL Server 2012 and doesn't exist in earlier versions Commented Sep 6, 2013 at 15:57
  • 2
    Also why do you have , \' instead of , '\'? Commented Sep 6, 2013 at 16:00

4 Answers 4

2

You can try like this:-

SELECT CustCity AS City, CustLastName + '\' + CustFirstName AS Customer
FROM Customers
ORDER BY CustCity, Customer

CONCAT function doesnot exist in SQL SERVER 2008.

Sign up to request clarification or add additional context in comments.

Comments

1

Do this instead:

SELECT CustCity AS City, CustLastName + '\' + CustFirstName AS Customer
FROM Customers
ORDER BY CustCity, Customer

Comments

1

CONCAT() is not a function of SQL Server 2008. If you want to concatenate the data in sql server, you should use the + sign:

SELECT CustCity AS City, CustLastName + ', ' + CustFirstName AS Customer
FROM Customers
ORDER BY CustCity, Customer;

See SQL Fiddle with Demo. If you want to include the \, then you can use:

SELECT CustCity AS City, CustLastName + ' \ ' + CustFirstName AS Customer
FROM Customers
ORDER BY CustCity, Customer

See Demo

Comments

0

Fairly certain your single quote ' is causing the problem. Problem is CONCAT only exists in SQL 2012 not 2008.

If you were using SQL 2012, the proper syntax would be.

Concat(CustLastName, '\', CustFirstName) AS Customer

3 Comments

CONCAT function doesnot exist in SQL SERVER 2008.
My bad. Updated the answer to reflect that it would work in 2012.
@RahulTripathi As Jack stated; it only exists in 2012 technet.microsoft.com/en-us/library/hh231515.aspx

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.