Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate two strings in SQL Server 2005

Tags:

sql-server

I want to concatenate the words "dummy's" and "dock".

How can I concatenate them in SQL Server 2005? Does it support double quotes?

like image 401
NoviceToDotNet Avatar asked Oct 29 '10 04:10

NoviceToDotNet


2 Answers

Try this:

DECLARE @COMBINED_STRINGS AS VARCHAR(50); -- Allocate just enough length for the two strings.  SET @COMBINED_STRINGS = 'rupesh''s' + 'malviya'; SELECT @COMBINED_STRINGS; -- Print your combined strings. 

Or you can put your strings into variables. Such that:

DECLARE @COMBINED_STRINGS AS VARCHAR(50),         @STRING1 AS VARCHAR(20),         @STRING2 AS VARCHAR(20);  SET @STRING1 = 'rupesh''s'; SET @STRING2 = 'malviya'; SET @COMBINED_STRINGS = @STRING1 + @STRING2;  SELECT @COMBINED_STRINGS;  

Output:

rupesh'smalviya

Just add a space in your string as a separator.

like image 168
yonan2236 Avatar answered Oct 14 '22 16:10

yonan2236


so if you have a table with a row like:

firstname lastname Bill      smith 

you can do something like

select firstname + ' ' + lastname from thetable 

and you will get "Bill Smith"

like image 42
John Boker Avatar answered Oct 14 '22 15:10

John Boker