Solved

How to concatenate entries?

Posted on 2010-11-12
3
254 Views
Last Modified: 2012-05-10
I have 2 tables
1. tblENQUIRY and
2. tblENQUIRY_FOLLOW_UP

The history contains the PK ENQUIRY_ID from the  tblENQUIRY

 tblENQUIRY tblENQUIRY_FOLLOW_UP SAMPLE DATA IN FOLLOW UP
What I need to do is create a new table with the 2 columns
ENQUIRY_ID and ENQ_FU_COMMENT

for each ENQUIRY_ID concatenate all of the individual lines in just one line.

like this ...
 what it should look like
I really appreciate help on this.

My solution does not work correctly.

best regards
0
Comment
Question by:STOCRIC
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
Comment Utility
Hi,

Check this.
Select 
	[Enquiry_ID],
	(Stuff((Select ', ' + ENQ_FU_COMMENT From tblEnquiry_Follow_Up E2 Where E1.Enquiry_ID = E2.Enquiry_ID FOR XML PATH('')),1,2,'')) as ENQ_FU_COMMENT
From tblEnquiry E1
Order By Enquiry_ID

Open in new window

0
 
LVL 19

Expert Comment

by:Bhavesh Shah
Comment Utility
For Sample
Declare @Aliases Table
(
	[FirstName] varchar(50) not null,
	[LastName] varchar(50) not null,
	[Alias] varchar(100) not null
)

Insert @Aliases
Select 'Clark','Kent','Superman'
Union All
Select 'Clark','Kent','Kal-El'
Union All
Select 'Clark','Kent','Gangbuster'
Union All
Select 'Clark','Kent','Supernova'
Union All
Select 'Clark','Kent','Nightwing'
Union All
Select 'Peter','Parker','Spiderman'
Union all
Select 'Peter','Parker','WebSligner'

Select * from @Aliases

Select Distinct
	[LastName],
	[FirstName],
	(Stuff((Select ', ' + Alias From @Aliases T2 Where T2.FirstName = T1.FirstName and T2.LastName = T2.LastName FOR XML PATH('')),1,2,'')) as Aliases
From @Aliases T1
Order By [LastName], [FirstName]

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now