Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Statement to return single string of rows

Status
Not open for further replies.

ousoonerjoe

Programmer
Jun 12, 2007
925
US
Have you looked at REPLACE()?
Code:
SELECT [Names] = AccountName,
	[Addresses] = AccountAddress,
	[Display] = AccountName + ' ' + REPLACE(REPLACE(AccountAddress, CHAR(13), ''), CHAR(10), '')
FROM tblAccounts;

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
The select statement you wrote returns 3 columns.

I need a single column returned with 1 value which is the concatenation of the rows.
 
Remove the columns you don't need. I only did that so you could see the original data and the formatted data side-by-side. [Display] is the formatted result.

Be sure to heed George's warning about string lengths. They can get ugly quickly if you're not careful.

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top