You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Erik Kron <er...@yahoo.com> on 2006/01/22 21:29:04 UTC

SQL query with "greater and equal" and "less and equal"

I have a table called rawattendancerecord.

There is a column in the table called logDate;

I want to be able to return log dates between 2 give
search date criteria. E.g. dates between fromDate and
toDate.


I can do a search from the command line (mysql) with
the following commands to return the right values.
e.g.

select * from rawattendancerecord where
logDate>='2005-10-10' and logDate<='2006-01-15';


How can I represent a similar query in ibatis?

In my RawAttendanceRecord.xml: (I am passing my search
range (from and to value) with fromDate to toDate
(properties) in the searchAttendanceRecords class.

<select id="getRawAttendanceRecordListRange"
resultMap="rawAttendanceRecordResult"
parameterClass="searchAttendanceRecords">
    select * from RAWATTENDANCERECORD where ...

  </select>

I just do not know the syntax to use. I have read
about <isGreaterEqual> and <isLessEqual>. But I cannot
seem to be able to use them appropriately.

Any help will be appreciated. I tried to search the
FAQ section, but the site is currently down.

Regards,
Erik

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: SQL query with "greater and equal" and "less and equal"

Posted by Larry Meadors <lm...@apache.org>.
This will work, too:

<select id="getRawAttendanceRecordListRange"
resultMap="rawAttendanceRecordResult"
parameterClass="searchAttendanceRecords">
   select * from RAWATTENDANCERECORD
   where logDate &gt;= #fromDate#
     and logDate &lt;= #toDate#
</select>

Larry


On 1/22/06, Jeff Butler <je...@gmail.com> wrote:
> <select id="getRawAttendanceRecordListRange"
> resultMap="rawAttendanceRecordResult"
> parameterClass="searchAttendanceRecords">
>    select * from RAWATTENDANCERECORD
>    where logDate <![CDATA[ >= ]]> #fromDate#
>      and logDate <![CDATA[ <= ]]> #toDate#
> </select>
>
> You need to enclose the <= and >= operators in XML CDATA sections to avoid
> breaking the XML syntax.
>
> The <isGreaterEqual> and is <isLessEqual> tags are for generating dynamic
> SQL based on run time values - not what you're doing here.
>
> Jeff Butler
>
>
>
> On 1/22/06, Erik Kron <er...@yahoo.com> wrote:
> > I have a table called rawattendancerecord.
> >
> > There is a column in the table called logDate;
> >
> > I want to be able to return log dates between 2 give
> > search date criteria. E.g. dates between fromDate and
> > toDate.
> >
> >
> > I can do a search from the command line (mysql) with
> > the following commands to return the right values.
> > e.g.
> >
> > select * from rawattendancerecord where
> > logDate>='2005-10-10' and logDate<='2006-01-15';
> >
> >
> > How can I represent a similar query in ibatis?
> >
> > In my RawAttendanceRecord.xml: (I am passing my search
> > range (from and to value) with fromDate to toDate
> > (properties) in the searchAttendanceRecords class.
> >
> > <select id="getRawAttendanceRecordListRange"
> > resultMap="rawAttendanceRecordResult"
> > parameterClass="searchAttendanceRecords">
> >    select * from RAWATTENDANCERECORD where ...
> >
> > </select>
> >
> > I just do not know the syntax to use. I have read
> > about <isGreaterEqual> and <isLessEqual>. But I cannot
> > seem to be able to use them appropriately.
> >
> > Any help will be appreciated. I tried to search the
> > FAQ section, but the site is currently down.
> >
> > Regards,
> > Erik
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
>
>

Re: SQL query with "greater and equal" and "less and equal"

Posted by Jeff Butler <je...@gmail.com>.
<select id="getRawAttendanceRecordListRange"
resultMap="rawAttendanceRecordResult"
parameterClass="searchAttendanceRecords">
   select * from RAWATTENDANCERECORD
   where logDate <![CDATA[ >= ]]> #fromDate#
     and logDate <![CDATA[ <= ]]> #toDate#
</select>

You need to enclose the <= and >= operators in XML CDATA sections to avoid
breaking the XML syntax.

The <isGreaterEqual> and is <isLessEqual> tags are for generating dynamic
SQL based on run time values - not what you're doing here.

Jeff Butler


On 1/22/06, Erik Kron <er...@yahoo.com> wrote:
>
> I have a table called rawattendancerecord.
>
> There is a column in the table called logDate;
>
> I want to be able to return log dates between 2 give
> search date criteria. E.g. dates between fromDate and
> toDate.
>
>
> I can do a search from the command line (mysql) with
> the following commands to return the right values.
> e.g.
>
> select * from rawattendancerecord where
> logDate>='2005-10-10' and logDate<='2006-01-15';
>
>
> How can I represent a similar query in ibatis?
>
> In my RawAttendanceRecord.xml: (I am passing my search
> range (from and to value) with fromDate to toDate
> (properties) in the searchAttendanceRecords class.
>
> <select id="getRawAttendanceRecordListRange"
> resultMap="rawAttendanceRecordResult"
> parameterClass="searchAttendanceRecords">
>    select * from RAWATTENDANCERECORD where ...
>
> </select>
>
> I just do not know the syntax to use. I have read
> about <isGreaterEqual> and <isLessEqual>. But I cannot
> seem to be able to use them appropriately.
>
> Any help will be appreciated. I tried to search the
> FAQ section, but the site is currently down.
>
> Regards,
> Erik
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>