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 |
|
JAdauto
Posting Yak Master
160 Posts |
Posted - 2006-01-30 : 00:55:24
|
| I dont know if it is possible, and I have not found any other examples of posts trying to do what I am doing. I have a table that holds all rooms assigned for an event.EventID------Resource20----------BallRoom20----------Terrace20----------Mixed Grille21----------BallRoom21----------Lounge22----------Mixed GrilleWhat I need to return is one string field containing all the rooms assigned for an event.So if I do something likeSelect Resource from EventResource where EventID = 20I need the results to beBallroom, Lounge, Mixed GrilleBut I cannot find anywhere if this is even possible. Thoughts or suggestions?Thanks so much,JAdauto |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2006-01-30 : 01:07:42
|
| Do this way..declare @resource varchar(800)Select @resource = coalesce(@resource + ',' + resource ,resource ) from EventResource where EventID = 20select @resource |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
JAdauto
Posting Yak Master
160 Posts |
Posted - 2006-01-31 : 00:28:41
|
| Thanks to both of you. IN fact, I read that link prior to posting and somehow I could not get what it was saying. Anyway, that solution is working perfectly, except I need to add a wrench to it. I really simplified the data structure. There are a few tables actually involved as they can assign rooms to different time types within an event. So they may have cocktails in one room, the meal in another, the reception back in the first room. Long story short, I need to add a Distinct in that somewhere so that I only get the room name once. But everywhere I try to add it, I get a syntax error. Suggestions?Thanks again |
 |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2006-01-31 : 00:57:09
|
| Try this..declare @resource varchar(800)Select @resource = coalesce(@resource + ',' + resource , resource ) from ( Select distinct resource from EventReSource where EventID = 20 ) dselect @resource |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-31 : 01:06:55
|
| Yes, using derived table is the only way in this caseMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|