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)
 Select Data

Author  Topic 

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-04-01 : 00:45:02
Hi All,

I had one table with one column.
that table had 10 rows.

I want one select query to select all the column data in one row with comma seperated.

thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-01 : 00:55:58
concatenate records without UDF


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-04-01 : 01:00:21
ok, thanks i will check
Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-04-01 : 05:48:24
Hi,

what i want is:
my table structure is

name
-------
name1
name2
name3
name4
name5

i had a table with one column and data like this.

but i want the output as:
name1, name2, name3, name4, name5

is it possible with query.
i did with cursor, but i have to do with query.

thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-01 : 06:03:09
[code]

SELECT STUFF(u.v,1,1,'')
FROM
(
SELECT ',' + name FROM @t FOR XML PATH(''))u(v)

output
--------------
name1,name2,name3,name4,name5

[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-04-01 : 06:23:50
so nice,
thank you very much
this only i want
Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-04-01 : 06:28:40
can you pls explain this, i mean what is u(v)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-01 : 07:41:24
quote:
Originally posted by asuni

can you pls explain this, i mean what is u(v)



they represent table column aliases

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-04-01 : 07:47:00
ok, thank you very much, you are genius.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-01 : 12:04:47
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -