You are here: Re: return into one string « MsSQL Server « IT news, forums, messages
Re: return into one string

Posted by Erland Sommarskog on 05/06/06 00:26

(cybergoth_0@yahoo.co.uk) writes:
> I have a table with a column called AccessTypes which contains a single
> letter.
>
> I want to return these accesstypes from a query into one string. e.g.
>
> if there were 3 entries of A, S and D
>
> I want to select them and instead of returning 3 rows, I want just 1
> string like "ASD"
>
> can it be done?

If you are on SQL 2000, you need to use a cursor. The trick with
SELECT @x = @x + 'd' may work, but the result of this expression is
undefined, so you may get something else.

On SQL 2005, you can use FOR XML PATH as shown in the link posted by
Mark.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация