Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Problem Using Date Paramenter in SQL Clause
Problem Using Date Paramenter in SQL Clause [message #626473] Wed, 22 September 2010 11:09 Go to next message
Emerson Souza is currently offline Emerson Souza
Messages: 2
Registered: September 2010
Junior Member
Hi friends, I'm new here.

I'm having a problem using a SQL statement that contains a date paramenter using the Where clause.

Take a look:
SELECT DATE_CREATED, ORDERNUMBER, CUSTOMER_NBR, CUSTOMER_NAME,
  FROM ORDEREDITEMS
  WHERE DATE(DATE_CREATED) = ?


Trying to run this statement on BIRT SQL Builder, it doesn't bring me back the result that I want.

This example starts a problem that I'll have using the Between clause using the date parameter like I wrote in the sample code.

How could I do a SQL statement on BIRT using this example?

Thanks in advance!
Re: Problem Using Date Paramenter in SQL Clause [message #627085 is a reply to message #626473] Wed, 22 September 2010 16:30 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Is DATE_CREATED a date? what did you define the ? as?
You can link the dataset parameter to a report parameter or you can
modify the query using script. Take a look at this example that
effectively does a between using a beforeOpen script on the dataset.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.21"
id="1">
<property name="author">Paul Clenahan</property>
<property name="createdBy">Eclipse BIRT Designer Version
2.5.2.v20100208 Build &lt;2.5.2.v20100210-0630></property>
<text-property name="title">Classic Models Sales Invoice
Report</text-property>
<property name="units">in</property>
<property name="layoutPreference">auto layout</property>
<list-property name="configVars">
<structure>
<property name="name">OrderNumber</property>
<property name="value">10201</property>
</structure>
</list-property>
<parameters>
<scalar-parameter name="StartDate" id="5">
<text-property name="displayName">Order Naumber</text-property>
<text-property name="helpText">Order date for the
invoice</text-property>
<property name="valueType">static</property>
<property name="isRequired">false</property>
<property name="dataType">date</property>
<property name="distinct">true</property>
<simple-property-list name="defaultValue">
<value type="javascript">BirtDateTime.today()</value>
</simple-property-list>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
<scalar-parameter name="EndDate" id="161">
<property name="valueType">static</property>
<property name="isRequired">false</property>
<property name="dataType">date</property>
<property name="distinct">true</property>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
</parameters>
<data-sources>
<oda-data-source
extensionID="org.eclipse.birt.report.data.oda.jdbc" name="Classic
Models" id="6">
<list-property name="privateDriverProperties">
<ex-property>
<name>contentBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>metadataBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
</list-property>
<property
name="odaDriverClass">org.eclipse.birt.report.data.oda.sampledb.Driver </property>
<property name="odaURL">jdbc:classicmodels:sampledb</property>
<property name="odaUser">ClassicModels</property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set
extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet "
name="Invoice Data" id="7">
<list-property name="columnHints">
<structure>
<property name="columnName">ORDERNUMBER</property>
<text-property
name="displayName">ORDERNUMBER</text-property>
</structure>
<structure>
<property name="columnName">ORDERDATE</property>
<text-property
name="displayName">ORDERDATE</text-property>
</structure>
<structure>
<property name="columnName">SHIPPEDDATE</property>
<text-property
name="displayName">SHIPPEDDATE</text-property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">ORDERDATE</property>
<property name="dataType">date</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">SHIPPEDDATE</property>
<property name="dataType">date</property>
</structure>
</list-property>
</structure>
<method name="beforeOpen"><![CDATA[this.queryText = "SELECT
ORDERNUMBER, ORDERDATE, SHIPPEDDATE FROM CLASSICMODELS.ORDERS ";

if(params["StartDate"].value != null &amp;&amp; params["EndDate"].value
!= null) {

this.queryText += "where orderdate >= '" + params["StartDate"].value +
"'and orderdate <= '" + params["EndDate"].value +"'";

}else{

if (params["StartDate"].value != null) {

this.queryText += "where orderdate = '" + params["StartDate"].value +"'";

}else{

this.queryText += "where orderdate = current_date";

}

}

this.queryText += " order by orderdate";
]]></method>
<property name="dataSource">Classic Models</property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="nativeName">ORDERNUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">ORDERDATE</property>
<property name="nativeName">ORDERDATE</property>
<property name="dataType">date</property>
<property name="nativeDataType">91</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">SHIPPEDDATE</property>
<property name="nativeName">SHIPPEDDATE</property>
<property name="dataType">date</property>
<property name="nativeDataType">91</property>
</structure>
</list-property>
<xml-property name="queryText"><![CDATA[SELECT

ORDERNUMBER,

ORDERDATE,

SHIPPEDDATE

FROM

CLASSICMODELS.ORDERS

where

orderdate < current_date


ORDER BY CLASSICMODELS.ORDERS.ORDERNUMBER]]></xml-property>
</oda-data-set>
</data-sets>
<styles>
<style name="BackgroundLightGray" id="2">
<property name="backgroundColor">#EAEAEA</property>
</style>
<style name="BackgroundBlue" id="3">
<property name="backgroundColor">#4B6987</property>
</style>
<style name="BackgroundYellow" id="4">
<property name="backgroundColor">#FAD764</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="8">
<property name="topMargin">1in</property>
<property name="leftMargin">1.25in</property>
<property name="bottomMargin">1in</property>
<property name="rightMargin">1.25in</property>
<page-footer>
<text id="9">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new
Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<table id="139">
<property name="dataSet">Invoice Data</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">ORDERDATE</property>
<text-property
name="displayName">ORDERDATE</text-property>
<expression
name="expression">dataSetRow["ORDERDATE"]</expression>
<property name="dataType">date</property>
</structure>
<structure>
<property name="name">ORDERNUMBER</property>
<text-property
name="displayName">ORDERNUMBER</text-property>
<expression
name="expression">dataSetRow["ORDERNUMBER"]</expression >
<property name="dataType">integer</property>
</structure>
<structure>
<property name="name">SHIPPEDDATE</property>
<text-property
name="displayName">SHIPPEDDATE</text-property>
<expression
name="expression">dataSetRow["SHIPPEDDATE"]</expression >
<property name="dataType">date</property>
</structure>
</list-property>
<column id="152"/>
<column id="153"/>
<column id="154"/>
<header>
<row id="140">
<cell id="141">
<label id="155">
<text-property
name="text">ORDERDATE</text-property>
</label>
</cell>
<cell id="142">
<label id="157">
<text-property
name="text">ORDERNUMBER</text-property>
</label>
</cell>
<cell id="143">
<label id="159">
<text-property
name="text">SHIPPEDDATE</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="144">
<cell id="145">
<data id="156">
<property
name="resultSetColumn">ORDERDATE</property>
</data>
</cell>
<cell id="146">
<data id="158">
<property
name="resultSetColumn">ORDERNUMBER</property>
</data>
</cell>
<cell id="147">
<data id="160">
<property
name="resultSetColumn">SHIPPEDDATE</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="148">
<cell id="149"/>
<cell id="150"/>
<cell id="151"/>
</row>
</footer>
</table>
</body>
</report>



On 9/22/2010 11:09 AM, Emerson Souza wrote:
> Hi friends, I'm new here.
>
> I'm having a problem using a SQL statement that contains a date
> paramenter using the Where clause.
>
> Take a look:
>
> SELECT DATE_CREATED, ORDERNUMBER, CUSTOMER_NBR, CUSTOMER_NAME,
> FROM ORDEREDITEMS
> WHERE DATE(DATE_CREATED) = ?
>
>
> Trying to run this statement on BIRT SQL Builder, it doesn't bring me
> back the result that I want.
>
> This example starts a problem that I'll have using the Between clause
> using the date parameter like I wrote in the sample code.
>
> How could I do a SQL statement on BIRT using this example?
>
> Thanks in advance!
Re: Problem Using Date Paramenter in SQL Clause [message #627093 is a reply to message #627085] Wed, 22 September 2010 16:49 Go to previous messageGo to next message
Emerson Souza is currently offline Emerson Souza
Messages: 2
Registered: September 2010
Junior Member
Hi Jason, tnks for reply me!

The DATE_CREATED column is Timestamp type. But I wanna run my query using Date type as I wrote before:
WHERE DATE(DATE_CREATED) = ?


So the marker ? is the parameter I have to pass to the query and then run it.

Looking at you example at this point:
this.queryText += "where orderdate >= '" + params["StartDate"].value + 
"'and orderdate <= '" + params["EndDate"].value +"'";


I understand you're telling me that this is the way to run a query using an AND clause with >= and <=, like a between...Humm, It sounds like a good idea.

I'll try it on and see if it's what I'm looking for.

Tnks for awhile.

Re: Problem Using Date Paramenter in SQL Clause [message #627179 is a reply to message #627093] Wed, 22 September 2010 17:39 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

BTW when you use a ? in the dataset this creates a dataset parameter not
a report parameter. You can tie a dataset parameter to a report
parameter in the dataset editor (parameters tab). The script example I
showed does not use dataset parameters but just report parameters.

Jason

On 9/22/2010 4:49 PM, Emerson Souza wrote:
> Hi Jason, tnks for reply me!
>
> The DATE_CREATED column is Timestamp type. But I wanna run my query
> using Date type as I wrote before:
> WHERE DATE(DATE_CREATED) = ?
>
> So the marker ? is the parameter I have to pass to the query and then
> run it.
>
> Looking at you example at this point:
> this.queryText += "where orderdate >= '" + params["StartDate"].value +
> "'and orderdate <= '" + params["EndDate"].value +"'";
>
> I understand you're telling me that this is the way to run a query using
> an AND clause with >= and <=, like a between...Humm, It sounds like a
> good idea.
>
> I'll try it on and see if it's what I'm looking for.
>
> Tnks for awhile.
>
>
Re: Problem Using Date Paramenter in SQL Clause [message #628774 is a reply to message #626473] Fri, 24 September 2010 01:39 Go to previous message
Chris  is currently offline Chris
Messages: 47
Registered: September 2010
Member
Jason,
I also had this problem but solved it in the following way.
1. set the parameter as a string and cast it in the query. the query became:
select public.transactions.transdate, public.transactions.originalgrossamt
from public.transactions
Where public.transactions.transdate>=cast(? as date).
2..Data set parameter data type was string.
3.public.transactions.transdate was type date
3.report parameter was set to string.
4. entered date as dd/mm/yyyy
It worked.

By the way I can copy and paste the XML code from BIRT into a file, but how do you load an XML file into BIRT?
Previous Topic:reason for dependency of org.eclipse.birt.report.designer.ui.ide on org.eclipse.jdt.core
Next Topic:Securtity in BIRT
Goto Forum:
  


Current Time: Thu Jul 31 22:00:32 EDT 2014

Powered by FUDForum. Page generated in 0.01610 seconds