Solved

How to concatenate entries?

Posted on 2010-11-12
3
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

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

Expert Comment

by:Bhavesh Shah
ID: 34120201
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
ID: 34120206
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

689 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