We help IT Professionals succeed at work.
Get Started

In SQL 2000 combine mulitple rows into a single row seperated by a semi colon

woodwyn asked
Last Modified: 2017-04-06
Unfortunately still on SQL 2000 here.  The following query creates #MSR4 with repeating values of keyWebItemAttributes, each with a unique PersonalizationAnswer.

SELECT p.keyWebItemAttributes, l.PersonalizationAnswer
FROM WebLinkPersonalizations l
INNER JOIN WebItemPersonalizations p ON l.keyWebItemPersonalizations=p.keyWebItemPersonalizations

I want to combine the all the Personalization records for keyWebItemAttributes into a temporary table. I cannot get XML to work here because of the SQL 2000 thing and COELESCE doesn't seem to allow for insertion into temp tables.  This gives an error at XML:
SELECT B.keyWebItemAttributes, STUFF((SELECT ', ' + A.Personalization FROM #MSR4 A
Where A.keyWebItemAttributes=B.keyWebItemAttributes FOR XML PATH('')),1,1,'') AS Personalizations
Group By B.keyWebItemAttributes

This gives me the error A SELECT INTO statement cannot contain a SELECT statement that assigns values to a variable.
DECLARE @Personalization CHAR(2000)
Set @Personalization=''
Select keyWebItemAttributes, @Personalization=@Personalization + Coalesce([Personalization]+ ', ','')
GROUP BY keyWebItemAttributes
Watch Question
Senior Developer
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
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