December 7, 2008 at 6:28 pm
What would be the ideal means of retrieving child records and then concatenating the value in a specific column so that its returned in a SELECT?
Let's say for example that you have a vendor database and each vendor has several contacts and you want to present the vendor information in a query for later use - such as exporting to Excel or publishing to the web via ASP. How would you get the contacts all together as one column?
Vendor Address City State Zip Contacts
ABC Liquor 123 Main St Orlando FL 32811 John Smith
April Jones
Mike Nesmith
Joan Heart
Chic-Fil-A 50 Conway Orlando FL 32862 David Smith
Vlad Parisi
Linda Robinson
I have built a user-defined function that successfully pulls the child records and returns them as a string, but I'm just wondering if there are other ways of doing this or better ways. I'm also really curious if its possible to write a SQL statement that automatically concatenates the values.
December 7, 2008 at 8:52 pm
Here's an excellent article on this very subject, by some guy who is too modest to promote himself here (:)): http://www.sqlservercentral.com/articles/Test+Data/61572/
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply