Student
------------------------
| Roll | Name | Address |
| 1 | Bikash | bbsr |
| 2 | Tapan | ctc |
| 3 | Saroj | puri |
| 4 | Manoj | bbsr |
Book Issue
-------------------------------------
| Roll | Book | Date |
| 1 | C# | 21/03/2012 |
| 2 | C programming | 21/03/2012 |
| 1 | Sql Server | 03/04/2012 |
| 2 | C++ | 03/04/2012 |
Result should be
---------------------------------
Roll Name Book Date
--------------------------------------------------------------------------------------------------------
1 Bikash C#,Sql Server 21/03/2012,03/04/2012
2 Tapan c programming,c++ 21/03/2012,03/04/2012
please give me solution. already i have used group by with role number but not working.

Sukesh MarlaPosted Aug 16, 2012, 11:19 AM
Bikash DasPosted Aug 16, 2012, 6:14 AM
Pradip PandeyPosted Aug 14, 2012, 10:16 AM
I just go through your query and found that u have to create 2 functions and a select query to get the desired result.
Jignesh TrivediPosted Aug 13, 2012, 11:57 PM
try....
just some modification on above query...
SELECT * FROM (
SELECT r.Roll, r.name,
STUFF((SELECT ','+ a.Book
FROM BookIssue a
WHERE a.Roll = r.Roll
FOR XML PATH(''), TYPE).value('.','VARCHAR(max)'), 1, 1, '') as books,
STUFF((SELECT ','+ convert(varchar(10),a.Date,103)
FROM BookIssue a
WHERE a.Roll = r.Roll
FOR XML PATH(''), TYPE).value('.','VARCHAR(max)'), 1, 1, '') as Dates
FROM Student r) A
Where A.books is not null
hope this will help you.
Sukesh MarlaPosted Aug 13, 2012, 12:33 PM
(
SELECT Student.Roll,Student.Name,
replace
(
(
SELECT BookIssue.Book as [data()]
FROM BookIssue
WHERE BookIssue.Roll=Student.Roll
ORDER BY BookIssue.Roll FOR xml path('')
)
, ' ', ','
)
as Books,
replace
(
(
SELECT BookIssue.Date as [data()]
FROM BookIssue
WHERE BookIssue.Roll=Student.Roll
ORDER BY BookIssue.Roll FOR xml path('')
),
' ', ','
) as Date
FROM Student
)DerivedStudents
where Books is not null
Hope It Helped. Please Check This is Currect Answer.