January 20, 2009 at 7:33 pm
Hi,
I'm having the following table
sno Author books
---------------------------------------
1 Emily Wuthering Heights
2 Steve once upon a time
3 Richie Travellers story
4 Emily Oliver Twist
5 Steve Dallas Ranger
6 Richie The Epilogue
I want to extract the information like below
sno Author books
---------------------------------------
1 Emily Wuthering Heights, Oliver Twist
2 Steve once upon a time, Dallas Ranger
3 Richie Travellers story,The Epilogue
Can any one advise me how to achieve this ?
Thanks
Sree
January 20, 2009 at 8:45 pm
hopefully, this is not homework, because if you submit this as your answer, and can't explain what it does, you'll get burned.
FOR XML has a neat way of getting values as a comma delimited list.
SELECT A.sno,A.Author
,STUFF(
(
SELECT ', ' + B.books
FROM @AllBooks B
WHERE A.Author= B.Author
FOR XML PATH(''))
,
1, 2, '')
FROM @AllBooks A
GROUP BY Author
Lowell
January 21, 2009 at 7:11 am
You can also check out the articles in Steve's Tame Those Strings series. Here's a search link for them:
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply