Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
nbalraj
Starting Member
21 Posts |
Posted - 2013-07-17 : 11:22:57
|
Hi,I have a table called tblBooks with the below fieldsbookid (pk), booktitle, bookdescriptionexample record1, 'SQL for Queries', 'Great book for queries'I also have another table called tblBooksuggestions with the below fieldssuggestionid (pk), bookid(fk),suggestiondescexample records1, 1, 'I recommend this book'2, 1, 'It is for beginners'The challenge i'm facing or the required output, for any given bookid the query need to return: booktitle, suggestiondesc (all in one field)'SQL for Queries', 'I recommend this book <br> It is for beginners'Thanks for any help. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-17 : 11:39:32
|
[code]SELECT b.booktitle,STUFF((SELECT CHAR(13) + CHAR(10) + suggestiondesc FROM tblBookSuggestions WHERE bookid = b.bookid ORDER BY suggestionid FOR XML PATH('')),1,2,'')FROM tblBooks bWHERE bookid = @bookid[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
nbalraj
Starting Member
21 Posts |
Posted - 2013-07-17 : 13:07:55
|
Thanks and it worked great. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-17 : 13:21:55
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|