You are here: Re: constructing strings from table « MsSQL Server « IT news, forums, messages
Re: constructing strings from table

Posted by Erland Sommarskog on 05/22/07 21:48

Oonz (arundhaj@gmail.com) writes:
> Hi friends,
> please help me in selecting values from the table
>
> the record is as follows:
> Id HomePhone WorkPhone Mobile Email
> 20 2323223 323232232 test@test.com
>
> i have to select values as follows.
>
> Id DeviceType DeviceInfo
> 20 HomePhone, Mobile, Email 2323223, 323232232, test@test.com
>
>
> the one solution is:
> select
> 'HomePhone, Mobile, Email' AS DeviceType
> HomePhone + ',' + WorkPhone + ',' + MobilePhone + ',' + Email AS
> DeviceInfo
> from table where Id = 20
>
> but here the work phone number is not available so that information
> has to be truncated...

Provided that WorkPhone is blank, the query above make sense to me.
The output would be "2323223,,323232232,test@test.com". But if the
double comma wasn't there, how would you know which number that is
missing?

If WorkPhone is NULL, the entire expression will be NULL. In this
case you must use coalesce(WorkPhone, '') and similar for the other
columns.



--
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

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