Solved

SQL Server select build string instead of list

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

Suggested Solutions

Title # Comments Views Activity
Oracle DB monitor SW 21 48
Why Delete * statement wont work with sql server ? 6 40
T-SQL: Do I need CLUSTERED here? 13 41
performance query 4 20
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.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

785 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