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

avatar image

Mohan
324 49 59 63

(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

avatar image

JohnM
12.8k 3 7 14

(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

SQL Server Central

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

Topics:

x1069

asked: Sep 16, 2012 at 05:38 PM

Seen: 668 times

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

Copyright 2016 Redgate Software. Privacy Policy