Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 concat results from a select query

Author  Topic 

mahdi87_gh
Yak Posting Veteran

72 Posts

Posted - 2010-09-28 : 03:45:29
hi
i have this query
select distinct moghaser from Tasadof

and the results will be
moghaser
--------------
naja
sales
moshtarek


how can i concat this rows like this: naja,sales,moshtarek

thank u

****<< I Love MTN.SH >>****

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-09-28 : 04:06:32
You can achieve this using pivot operator.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-09-28 : 04:57:10
[code]
declare @tbl as table(val varchar(40))
insert into @tbl
select 'selectnaja'union
select 'sales'union
select 'moshtarek'

declare @val varchar(max)=''
select @val=@val +',' + val from @tbl
select stuff(@val,1,1,'')

[/code]

PBUH

Go to Top of Page

mahdi87_gh
Yak Posting Veteran

72 Posts

Posted - 2010-09-28 : 14:04:44
thanks dude

****<< I Love MTN.SH >>****
Go to Top of Page
   

- Advertisement -