• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

query list into a string

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
LeeHopkins
Asked:
LeeHopkins
  • 2
  • 2
1 Solution
 
DonKronosCommented:
do something like this:

declare @list varchar(1000)

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

set @list = substring(@list,1, (len(@list) - 1))
0
 
LeeHopkinsAuthor Commented:
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
 
LeeHopkinsAuthor Commented:
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
 
DonKronosCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now