Calculated field in a query

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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories