Sign in

E-mail *, (xx@domain.com)
Password *

Register | Forgot password

Queries with multiple rows per record

The "WCB: Java development" forum contains threads on issues that are related to Java while programming a WCB (WebManager Component Bundle). If you have questions that have impact on Java code, post them in this forum. Some example topics: authorization, the different component types, setting up component dependencies, data access, and so forth.

Answered
Not marked as answered yet

Forums  >  WCB: Java development  >  Queries with multiple rows per record


Author Queries with multiple rows per record
Cthulhu



Posts: 198

Posted: 26-01-2010 08:41

Hope the title makes sense.

On our sites, we have a number of queries that return two or three rows per record - books, in this case. A record is a book, and the multiple rows are returned because a book can have multiple authors. The join with the authors table results in multiple rows.

This also results in multiple books being shown in overviews like recently published books, and this has been bothering us for a while.

The main question is: Is there a neat way to catch this in the presentation layer? (both JSP(F) as XSL). We've fixed this in the 'book detail' query, but that's relatively easy because it's one book. It becomes a different story when there's multiple books, because then it becomes more difficult to separate two records from each other.

Does anyone else have experience with this problem, and found a proper solution?

Yes, I already know that this should be handled in the layer between the DB and the view, but we have no such layer at this time. We use straight query elements whose results are sent to a JSP template. In a distant future we'll develop a middleware layer, but that's a future far, far away, it seems. In the meantime, we'll need a solution for books being displayed multiple times when they have multiple authors.

Any ideas?

PeterK



Posts: 9

Posted: 02-03-2010 13:10

Hi,

You could try to create a stored procedure that flattens the results as described on this page.

Cheers.


CREATE PROCEDURE [dbo].[bookauthors] @id int, @authors varchar(1000) OUTPUT

AS
BEGIN
SET NOCOUNT OFF;

set @authors = ''

select
@authors = @authors + cast(j.author as varchar(10)) + ', '
from
bookauthor j

inner join book o2
on o2.id = j.book
where
j.book = @id

return
END

Back to top

New message: "Queries with multiple rows per record"
Message:
bold boitalicd underline url quote code smile cool eek grin mad razz sad wink
 
© 2010 GX creative online development B.V.

Disclaimer

This website (GXdeveloperweb.com) may discuss or contain opinions, (sample) coding, software or other information that does not include GX official interfaces, instructions or guidelines and therefore is not supported by GX. Changes made based on this information are not supported.  GX will not be held liable for any damages caused by using or misusing the information, software, instructions, code or methods suggested on this website, and anyone using these methods does so at his/her own risk. GX offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this website, including any liability resulting from incompatibility between the content of this website and the materials and services offered by GX. By using this website you will not hold, or seek to hold, GX responsible or liable with respect to the content of this website.