Enterprise JavaBeans

Moderators: None (Apply to moderate this forum)
Number of threads: 58
Number of posts: 93

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Calculated field in a query Posted by bryndabella on 2 Jun 2008 at 1:16 PM
Hi,

To begin with I am just learning EJB and JAVA so please bear with me. I want to create a calculated field in a query from two fields in the table being queried, using SQL I would write the query like this:

SELECT ledgerdate, description, quantity, unitprice, [quantity*unitprice] FROM ledger

I have created a class called ViewLedger to contain my results, it has the following elements:

DATE ledgerdate,
STRING description,
INTEGER quantity,
BIGDECIMAL unitprice,
BIGDECIMAL amount

The query that I have been attempting that fails is:

SELECT NEW ViewLedger(l.ledgerdate, l.description, l.quantity, l.unitprice, l.quantity*l.unitprice) FROM Ledger l

The error says that there is an unexpected * in the query

The following do not work either:

SELECT NEW ViewLedger(l.ledgerdate, l.description, l.quantity, l.unitprice, (l.quantity*l.unitprice)) FROM Ledger l

The error says there is an unexpected ( in the query.

SELECT NEW ViewLedger(l.ledgerdate, l.description, l.quantity, l.unitprice, [l.quantity*l.unitprice]) FROM Ledger l

The error says there is an unexpected [ in the query.

Any help would be greatly appreciated.

Thanks.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.