Solved

SQL Server select build string instead of list

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

867 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

22 Experts available now in Live!

Get 1:1 Help Now