Solved

SQL Server select build string instead of list

Posted on 2013-01-18
3
284 Views
Last Modified: 2013-01-18
Using this code
SELECT C.[Client Name] + '<br />' Client
FROM dbo.ClientVisitTracking cvt
JOIN Client C
	ON	cvt.[Client ID] = C.[Client ID]
WHERE CVT.[Account Executive] = 'jfay'

Open in new window


I get this list

Client
St. Joseph Medical Center - Chicago<br />
St. Joseph Medical Center - Houston<br />

I would like to get this

Client
St. Joseph Medical Center - Chicago<br />St. Joseph Medical Center - Houston<br />
0
Comment
Question by:lrbrister
[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
3 Comments
 
LVL 41

Accepted Solution

by:
ralmada earned 500 total points
ID: 38793640
declare @str varchar(max)


SELECT @str = coalesce(@str, '') + C.[Client Name] + '<br />'
FROM dbo.ClientVisitTracking cvt
JOIN Client C
      ON      cvt.[Client ID] = C.[Client ID]
WHERE CVT.[Account Executive] = 'jfay'

print @str
0
 

Author Closing Comment

by:lrbrister
ID: 38793647
Perfect. Thanks
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38793649
this is known as "group_concat", though not a really build-in function like in MySQL.

see a CLR implementation:
http://groupconcat.codeplex.com/
see sql codes alternatives:
http://stackoverflow.com/questions/451415/simulating-group-concat-mysql-function-in-microsoft-sql-server-2005
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

628 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