x
login about faq Site discussion (meta-askssc)

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 '12 at 05:38 PM in Default

Mohan gravatar image

Mohan
314 18 30 43

(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 '12 at 06:14 PM

JohnM gravatar image

JohnM
4.5k 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.

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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x914

asked: Sep 16 '12 at 05:38 PM

Seen: 262 times

Last Updated: Sep 16 '12 at 06:14 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.