x

Address concatenation

Eno ename addr1 addr2 addr2 city state 1 aaaa xxxx yyyy zzzz tttt rr 2 bbb yyyy zzzz aaaa jjjj rr

output should look like below

eno ename address

1 aaaa xxxx yyyy zzzz tttt rr

2 bbbb yyyy zzzz aaaa jjjj rr

more ▼

asked Sep 16, 2012 at 05:38 PM in Default

Mohan gravatar image

Mohan
324 37 55 60

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Is this what you're looking for?

CREATE TABLE #temp (
 id INT
 , NAME VARCHAR(50)
 , addr1 VARCHAR(50)
 , addr2 VARCHAR(50)
 , addr3 VARCHAR(50)
 , city VARCHAR(50)
 , STATE VARCHAR(50)
 )
GO

INSERT #temp (
 id, NAME, addr1, addr2, addr3, city, STATE
 )
SELECT 1, 'aaaa', 'xxxx', 'yyyy', 'zzzz', 'tttt', 'rr'
UNION
SELECT 2, 'bbb', 'yyyy', 'zzzz', 'aaaa', 'jjjj', 'rr'
GO

SELECT id
 , NAME
 , addr1 + ' ' + addr2 + ' ' + addr3 + ' ' + city + ' ' + STATE AS 'Address'
FROM #temp
GO
more ▼

answered Sep 16, 2012 at 06:14 PM

JohnM gravatar image

JohnM
6.6k 1 3 7

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x985

asked: Sep 16, 2012 at 05:38 PM

Seen: 538 times

Last Updated: Sep 16, 2012 at 06:14 PM