<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Calculated field in a query' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Calculated field in a query' posted on the 'Enterprise JavaBeans' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sun, 19 May 2013 04:50:44 -0700</pubDate>
    <lastBuildDate>Sun, 19 May 2013 04:50:44 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Calculated field in a query</title>
      <link>http://www.programmersheaven.com/mb/EJBeans/372373/372373/calculated-field-in-a-query/</link>
      <description>Hi,&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
SELECT ledgerdate, description, quantity, unitprice, [quantity*unitprice] FROM ledger&lt;br /&gt;
&lt;br /&gt;
I have created a class called ViewLedger to contain my results, it has the following elements:&lt;br /&gt;
&lt;br /&gt;
DATE ledgerdate, &lt;br /&gt;
STRING description,&lt;br /&gt;
INTEGER quantity,&lt;br /&gt;
BIGDECIMAL unitprice,&lt;br /&gt;
BIGDECIMAL amount&lt;br /&gt;
&lt;br /&gt;
The query that I have been attempting that fails is:&lt;br /&gt;
&lt;br /&gt;
SELECT NEW ViewLedger(l.ledgerdate, l.description, l.quantity, l.unitprice, l.quantity*l.unitprice) FROM Ledger l&lt;br /&gt;
&lt;br /&gt;
The error says that there is an unexpected * in the query&lt;br /&gt;
&lt;br /&gt;
The following do not work either:&lt;br /&gt;
&lt;br /&gt;
SELECT NEW ViewLedger(l.ledgerdate, l.description, l.quantity, l.unitprice, (l.quantity*l.unitprice)) FROM Ledger l&lt;br /&gt;
&lt;br /&gt;
The error says there is an unexpected ( in the query.&lt;br /&gt;
&lt;br /&gt;
SELECT NEW ViewLedger(l.ledgerdate, l.description, l.quantity, l.unitprice, [l.quantity*l.unitprice]) FROM Ledger l&lt;br /&gt;
&lt;br /&gt;
The error says there is an unexpected [ in the query.&lt;br /&gt;
&lt;br /&gt;
Any help would be greatly appreciated.&lt;br /&gt;
&lt;br /&gt;
Thanks.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/EJBeans/372373/372373/calculated-field-in-a-query/</guid>
      <pubDate>Mon, 02 Jun 2008 13:16:29 -0700</pubDate>
      <category>Enterprise JavaBeans</category>
    </item>
  </channel>
</rss>