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.
| Author |
Topic |
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2007-11-29 : 11:15:03
|
| HiIn the database I am using there is an option for a person to choose multiple options ie. a person choosing a form of conact, such as fone and mail.When I search this information it will show two records for the person each one showing the different contact method. Is there a function that returns a string of values that have been selected on one line, so there is no need for there to be multiple records?Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2007-11-29 : 11:41:24
|
| suppose you have person table asPerson(PersonID,PersonName)and contact as Contacts(ContactID,ContactName,PersonID)using this query...select p.PersonName,LEFT(ContactList,LEN(ContactList)-1) AS 'Contacts'-- strip the last ',' from the listfromPerson p cross apply(select c.ContactName + ',' as [text()]from Contacts cwhere c.PersonID = p.PersonIDorder by c.ContactNamefor xml path('')) Temp(ContactList)goyou will get result asPersonName ContactsP1 phoneP2 phone,mail... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-30 : 01:36:04
|
| http://sqlteam.com/forums/topic.asp?TOPIC_ID=81254MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|