Solved

select distinc @list=

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Binding error when running a view SQL Server 3 26
SQL SERVER - Index skipped a number 2 26
Row insertion failed. Array 5 46
MS SQL SERVER and ADODB.commands 8 19
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

839 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