Solved

select distinc @list=

Posted on 2004-08-16
5
457 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 111 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

735 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