Tuesday, March 20, 2012

Could you write a special stored procedure for me in SQL 2005?

When I execute the SQL "select TagName from Th_TagTable where IDTopic=@.IDTopic" , it return several rows such as
TagName= http://www.hothelpdesk.com

TagName= http://www.hellocw.com
TagName= http://www.supercoolbookmark.com

I hope there is a stored procedure which can join all TagName into a single string and return,
it means when I pass @.IDTopic to the stored procedure, it return "http://www.hothelpdesk.com, http://www.hellocw.com, http://www.supercoolbookmark.com"

How can write the stored procedure?

The best answer to this question is in this post: http://databases.aspfaq.com/general/how-do-i-concatenate-strings-from-a-column-into-a-single-row.html

If you are using 2005, be sure and use the FOR XML PATH solution. It does not have of the issues that the 2000 solutions did, unless you used a cursor (which is equally heinous Smile

No comments:

Post a Comment