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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenate all fields into one text field

Status
Not open for further replies.

Chumley40

Programmer
Jan 24, 2005
71
0
0
US
I am trying to do this. Take a table that returns one colum like this

bobby
suzi
debbie

I want to create one field from this that has
bobby,suzi,debbie

how do I write this?
 
Code:
DECLARE @Test varchar(max) -- varchar(8000) if you use SQL Server 2000

SELECT @Test = ISNULL(@Test+',', '') + NameOfTheColumn
FROM YourTable

SELECT @Test

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Just to add to Boris's suggestion....

[tt][blue]
WHERE NameOfTheColumn > ''
[/blue][/tt]

This will filter NULLs (which may give incomplete results) and empty strings (which would lead to double commas).



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top