0

Hi there!

I have the following SELECT Statment:

SELECT IDLivro,Titulo
	,LEFT(Nome, LEN(Nome) - 2) AS Nome
	,LEFT(Categoria, LEN(Categoria) - 2) AS Categoria
	,Posicao
    ,Classificacao
    ,Comentario
    
FROM
(
	SELECT L.Titulo
		,(
			SELECT A.Nome + ' ; ' AS "text()"
			FROM dbo.Autor A
				JOIN dbo.LivroAutor LA
					ON A.IDAutor = LA.IDAutor
			WHERE LA.IDLivro = L.IDLivro
			ORDER BY A.Nome DESC
			FOR XML PATH('')
		) AS Nome
		,(
			SELECT C.Categoria + ' ; ' AS "text()"
			FROM dbo.Categoria C
				JOIN dbo.LivroCategoria LC
					ON C.IDCategoria = LC.IDCategoria
			WHERE LC.IDLivro = L.IDLivro
			ORDER BY C.Categoria DESC
			FOR XML PATH('')
		) AS Categoria
		,L.Posicao
		,L.Classificacao
		,L.IDLivro
		,L.Comentario
	FROM dbo.Livro L
) D

That gives me that:
[img]http://img18.imageshack.us/img18/3556/antesu.jpg[/img]

and i need that:
[img]http://img33.imageshack.us/img33/7030/depoisi.jpg[/img]
(Edited in PAINT lol)

My structure is:
[img]http://img33.imageshack.us/img33/9710/structureu.jpg[/img]

Can you help me please?
Thanks

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by pee2002
0

This solved the problem:

CREATE VIEW VistaGERAL AS
SELECT D.IDLivro
      ,Titulo
      ,LEFT(Nome, LEN(Nome) - 2) AS Nome
      ,LEFT(Categoria, LEN(Categoria) - 2) AS Categoria
      ,Posicao
      ,Classificacao
      ,D.Comentario
      ,E.Pessoa
FROM
(
    SELECT L.Titulo
        ,(
            SELECT A.Nome + ' ; ' AS "text()"
            FROM dbo.Autor A
                JOIN dbo.LivroAutor LA
                    ON A.IDAutor = LA.IDAutor
            WHERE LA.IDLivro = L.IDLivro
            ORDER BY A.Nome DESC
            FOR XML PATH('')
        ) AS Nome
        ,(
            SELECT C.Categoria + ' ; ' AS "text()"
            FROM dbo.Categoria C
                JOIN dbo.LivroCategoria LC
                    ON C.IDCategoria = LC.IDCategoria
            WHERE LC.IDLivro = L.IDLivro
            ORDER BY C.Categoria DESC
            FOR XML PATH('')
        ) AS Categoria
        ,L.Posicao
        ,L.Classificacao
        ,L.IDLivro
        ,L.Comentario
    FROM dbo.Livro L
) AS D
LEFT JOIN EmprestimoLivro AS L
  ON D.IDLivro = L.IDLivro
LEFT JOIN Emprestado AS E  
  ON L.IDEmprestimo = E.IDEmprestimo;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.