We help IT Professionals succeed at work.
Get Started

Can I combine the results of one column of multiple records into one varaiable in SQL?

woodwyn asked
Last Modified: 2012-05-12
I want to create a stored procedure that returns one text string that is the combination of a queries results from the same column.  Is there a way to do this in SQL?  The production server is still at SQL 2000.  I will have no idea how many results I will need to combine with each call.

For Example:
DECLARE @cString AS varchar(8000)
SET @cString=''
SELECT CompanyName INTO #MSR FROM Company
   IF @cString = ''
      @cString = RTRIM(#MSR.CompanyName)
    @cString = @cString+', '+RTRIM(#MSR.CompanyName)
Watch Question
This problem has been solved!
Unlock 3 Answers and 9 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE