Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server select build string instead of list

Posted on 2013-01-18
3
Medium Priority
?
287 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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

715 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