?
Solved

query list into a string

Posted on 2006-04-04
6
Medium Priority
?
225 Views
Last Modified: 2010-03-19
I have a query that brings back a list of email address based on some factor I need to creat a list
x@.com;y@.com;z@.com........
from a result set
x@.com
y@.com
z@.com
......
with out haveing to do a cursor
0
Comment
Question by:LeeHopkins
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:DonKronos
ID: 16375822
do something like this:

declare @list varchar(1000)

select @list = @list + emailaddress + ';' from table1

set @list = substring(@list,1, (len(@list) - 1))
0
 

Author Comment

by:LeeHopkins
ID: 16375874
no go

declare @list varchar(1000)

select @list = @list + p_emailaddress + ';' from Purge_Email

set @list = substring(@list,1, (len(@list) - 1))

it should have returned 4 records
0
 

Author Comment

by:LeeHopkins
ID: 16375964
declare @list varchar(1000)
select @list = Coalesce(@list + ', ', '') + p_emailaddress
from purge_email where charindex('input_output',P_customer)> 0
select @list

Almost works but not giving distinct
0
 
LVL 15

Accepted Solution

by:
DonKronos earned 200 total points
ID: 16380810
declare @list varchar(1000)
select @list = Coalesce(@list + ', ', '') + distinctaddr.p_emailaddress
from (select distinct p_emailaddress from purge_email where charindex('input_output',P_customer)> 0) as distinctaddr
select @list
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

850 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