Solved

select distinc @list=

Posted on 2004-08-16
5
450 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
  • 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 142

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 142

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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…
Viewers will learn how the fundamental information of how to create a table.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now