October 16, 2017 at 7:04 am
Hi guys,
I would like to concatenate two columns which have a space between them. I keep getting an error message. the code is below. any help would be appreciated.
CONCAT(First Name, ' ', Last Name)
October 16, 2017 at 7:09 am
Without the error message, this is a guess, but do you column names have spaces in them? To refer to a field with whitespace in, you need to encapsulate the name in square brackets ([ ]). For example:CONCAT([First Name], ' ', [Last Name])
Personally, where possible, I would avoid using column names with whitespace in. Use CamelCase, or Underscores instead.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
October 16, 2017 at 7:22 am
Without the error message, this is a guess, but do you column names have spaces in them? To refer to a field with whitespace in, you need to encapsulate the name in square brackets ([ ]). For example:CONCAT([First Name], ' ', [Last Name])
Personally, where possible, I would avoid using column names with whitespace in. Use CamelCase, or Underscores instead.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
October 16, 2017 at 8:16 am
I am still getting an error message:
Msg 189, Level 15, State 1, Line 45
The concat function requires 2 to 254 arguments.
October 16, 2017 at 8:34 am
adan950 - Monday, October 16, 2017 8:16 AMI am still getting an error message:
Msg 189, Level 15, State 1, Line 45
The concat function requires 2 to 254 arguments.
You have posted in the 2008 forum and I don't think CONCAT() works in 2008.
Thanks
October 16, 2017 at 8:38 am
adan950 - Monday, October 16, 2017 8:16 AMI am still getting an error message:
Msg 189, Level 15, State 1, Line 45
The concat function requires 2 to 254 arguments.
CREATE TABLE names
(
[First Name] VARCHAR(20) ,
[Last Name] VARCHAR(20)
);
INSERT INTO dbo.names ( [First Name] ,
[Last Name]
)
VALUES ( 'John', 'Smith' );
SELECT CONCAT([First Name], ' ', [Last Name])
FROM names;
This code works fine. Did you copy/paste your code segment in your initial message, or type it yourself? You might not have reproduced the exact code you're having a problem with.
Without the actual code you're using we're just guessing.
October 16, 2017 at 9:02 am
adan950 - Monday, October 16, 2017 8:16 AMI am still getting an error message:
Msg 189, Level 15, State 1, Line 45
The concat function requires 2 to 254 arguments.
What is the exact SQL you're running? For example, this works fine:CREATE TABLE #test ([First name] varchar(10), [Last name] varchar(10));
INSERT INTO #test VALUES ('Joe','Bloggs');
SELECT CONCAT([First name],' ',[Last Name]) AS FullName
FROM #test;
DROP TABLE #test;
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
October 26, 2017 at 8:11 pm
NorthernSoul - Monday, October 16, 2017 8:34 AMadan950 - Monday, October 16, 2017 8:16 AMI am still getting an error message:
Msg 189, Level 15, State 1, Line 45
The concat function requires 2 to 254 arguments.You have posted in the 2008 forum and I don't think CONCAT() works in 2008.
Thanks
I think that's likely the answer to the problem.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 1, 2017 at 11:52 am
Not sure if this is the answer but I am using the following in 2008 and it works great
TableName.[First Name] + ' ' + TableName.Last Name
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply