Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

select distinc @list=

Posted on 2004-08-16
5
Medium Priority
?
465 Views
Last Modified: 2008-01-09
-- how to get result  ',a,afsd' ?
select "id"=cast('a' as varchar(10)) into #a
insert into #a values ( 'afds')
insert into #a values ( 'a')
declare @text varchar (1000)
set @text=''
select distinct @text= @text +',' + id from #a order by id
select @text
0
Comment
Question by:ill
[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
  • 2
5 Comments
 
LVL 12

Author Comment

by:ill
ID: 11817999
almost forgot, without temporary table "select distinct * into #b from #a".
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 11818224
I am sorry, but I don't see what you problem is, what error you have etc.
Can you precise more, because the comment mentionnes a table #b which I don't see where it comes from and what it has to do with the "question"...

CHeers
0
 
LVL 12

Author Comment

by:ill
ID: 11818272
current result of above query is
",afds"
i need it to be
",a,afds"


@#b table. i can do it with temporary table table with distinct values from table #a.
----
select "id"=cast('a' as varchar(10)) into #a
insert into #a values ( 'afds')
insert into #a values ( 'a')
select distinct * into #b from #a
declare @text varchar (1000)
set @text=''
select distinct @text= @text +',' + id from #b order by id
select @text
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 444 total points
ID: 11818332
ok, now I got it.

Instead of SELECT DISTINCT use GROUP BY

select "id"=cast('a' as varchar(10)) into #a
insert into #a values ( 'afds')
insert into #a values ( 'a')
declare @text varchar (1000)
set @text=''
select  @text= @text +',' + id from #a group by id order by id
select @text

CHeers
0
 
LVL 12

Author Comment

by:ill
ID: 11818354
shame on me :/. that's, what i was looking for.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

609 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