Hi all, this'll be my first post here, hopefully I'll get this right and someone can help.I'm trying to generate a subquery that will take a set of one-column rows and concatenate them into a single cell.I've adapted from this article (http://www.sqlteam.com/item.asp?ItemID=2368) the following code:DECLARE @topicList varchar(200)SELECT @topicList = COALESCE(@topicList + ', ', '') + MAB_topics.topic_nameFROM MAB_topicsSELECT @topicList
that produces a list of all the topic_names in the database seperated by commas. That's fine.I couldn't follow all the code in this thread (http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=18363) but I was able to extract and modify this code:DECLARE @topicList varchar(200)SELECT MAB_topics.topic_nameINTO #tmpFROM MAB_topics, MAB_articleIndexWHERE MAB_articleIndex.article_ID = 76 AND MAB_topics.topic_ID = MAB_articleIndex.topic_IDSELECT * FROM #tmpdrop table #tmp
which returns the two topic_names that I'd expect. (Note: this is my very first day declaring variables and using temp tables.) So I keep thinking that the following code would combine the two above working functions. But, when I run it in Query Analyzer, it just returns "(2 row(s) affected)" instead of a recordset.DECLARE @topicList varchar(200)SELECT MAB_topics.topic_nameINTO #tmpFROM MAB_topics, MAB_articleIndexWHERE MAB_articleIndex.article_ID = 76 AND MAB_topics.topic_ID = MAB_articleIndex.topic_IDSELECT @topicList = COALESCE(@topicList + ', ', '') + #tmp.topic_nameFROM #tmpdrop table #tmp
What am I doing wrong? I'm sure it's something simple but I've been reading and trying and reading and trying for a few hours and haven't gotten it yet. The ideal response would figure out what I'm trying to do as well as what my mistake is and explain how I'm misthinking. A close second would be just fixing my code. :)Thanks in advance,Chris