Solved

SQL Server select build string instead of list

Posted on 2013-01-18
3
273 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
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 142

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

758 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

23 Experts available now in Live!

Get 1:1 Help Now