I am looking for an output like:
|  BOOK | DETAILS                                                           |
|-------|-------------------------------------------------------------------|
| BookA | COD_100,A,mary.jane||COD_101,P,silvia.poff                        |
| BookB | COD_102,A,andrea.maya                                             |
What I am getting is all the results for all the lines, instead, like:
|  BOOK |  DETAILS                                                          |
|-------|-------------------------------------------------------------------|
| BookA | COD_100,A,mary.jane||COD_101,P,silvia.poff||COD_102,A,andrea.maya |
| BookB | COD_100,A,mary.jane||COD_101,P,silvia.poff||COD_102,A,andrea.maya |
I had a question (Looping lines in SQL) almost the same, but I couldn't reproduce it in this case. Bellow is the the Fiddle I used to get the data:
MS SQL Server 2008 Schema Setup:
CREATE TABLE books 
  (
    book varchar(10),
    book_group varchar(10),
    status varchar(10)
  );
INSERT INTO books (book, book_group, status)
VALUES
('BookA', 'A', 'open'),
('BookB', 'A', 'open'),
('BookC', 'B', 'open'),
('BookD', 'C', 'open'),
('BookE', 'D', 'open');
CREATE TABLE books_underanalisys 
  (
    book varchar(10)
  );
INSERT INTO books_underanalisys (book)
VALUES
('BookA'),
('BookB'),
('BookC'),
('BookD'),
('BookE');
CREATE TABLE books_underanalisys_PlanA
  (
    book varchar(10),
    ID_books_underanalisys_PlanA varchar(10)
  );
INSERT INTO books_underanalisys_PlanA (book, ID_books_underanalisys_PlanA)
VALUES
('BookA', '100'),
('BookA', '101'),
('BookB', '102'),
('BookC', '103'),
('BookC', '104');
CREATE TABLE books_underanalisys_PlanA_detail 
  (
    ID_books_underanalisys_PlanA_detail varchar(10),
    COD_books_underanalisys_PlanA_detail varchar(10),
    status varchar(1),
    username varchar(100)
  );
INSERT INTO books_underanalisys_PlanA_detail (ID_books_underanalisys_PlanA_detail, COD_books_underanalisys_PlanA_detail, status, username)
VALUES
('100', 'COD_100', 'A', 'mary.jane'),
('101', 'COD_101', 'P', 'silvia.poff'),
('102', 'COD_102', 'A', 'andrea.maya'),
('103', 'COD_103', 'A', 'johan.kin'),
('104', 'COD_104', 'P', 'hingo.trunk');
Query 1:
SELECT
    books_underanalisys .book AS Book,
    STUFF((
SELECT
    '||' + books_underanalisys_PlanA_detail.COD_books_underanalisys_PlanA_detail + ',' + books_underanalisys_PlanA_detail.status + ',' + books_underanalisys_PlanA_detail.username AS [text()]
FROM
    books_underanalisys_PlanA right join books_underanalisys_PlanA_detail on books_underanalisys_PlanA.ID_books_underanalisys_PlanA = books_underanalisys_PlanA_detail.ID_books_underanalisys_PlanA_detail,
    books_underanalisys ,
    books
WHERE
    books_underanalisys_PlanA.book = books_underanalisys .book
AND books_underanalisys_PlanA.book = books.book
AND books.book_group = 'A'
AND books.status <> 'closed'
FOR XML PATH('')), 1, 2, '' ) AS DETAILS
FROM
    books_underanalisys_PlanA right join books_underanalisys_PlanA_detail on books_underanalisys_PlanA.ID_books_underanalisys_PlanA = books_underanalisys_PlanA_detail.ID_books_underanalisys_PlanA_detail,
    books_underanalisys ,
    books
WHERE
    books_underanalisys_PlanA.book = books_underanalisys .book
AND books_underanalisys_PlanA.book = books.book
AND books.book_group = 'A'
AND books.status <> 'closed'
GROUP BY
    books_underanalisys .book
|  BOOK |                                                           DETAILS |
|-------|-------------------------------------------------------------------|
| BookA | COD_100,A,mary.jane||COD_101,P,silvia.poff||COD_102,A,andrea.maya |
| BookB | COD_100,A,mary.jane||COD_101,P,silvia.poff||COD_102,A,andrea.maya |
 
     
    