I’m using coalesce to return a string of names and when I run it as a single query, I’ve got no problem, but when I want to put it in a larger query, I get a little stumped.
Below is the bit that works:
DECLARE @return varchar(200)
SELECT @return = COALESCE(@return + ', ', '') +
CAST((select FileAs) AS varchar(30))
from Objects
where ObjectId in (select objectid from dbo.Get_XML_Links(2335))
select @return
But I want to add the list of names into a larger query as follows:
select det.Description,
StartTime,
EndTime,
THE STRING OF NAMES
from DiaryEvents de
inner join DiaryEventTypes det on det.DiaryEventTypeID = de.EventTypeID
where EventTypeID in (29,40)
I can’t quite see what I need to do (or if it is possible in this format!)
Thanks to a comment above and a very handy article on SQL Authority, I’ve worked it out as follows: