You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Eka Gautama <ek...@seatech.com> on 2006/08/08 14:14:25 UTC
ORDER BY CLAUSE
HI guys,
I am having problem currently. I have a very simple query with ORDER BY clause, but I want to give parameter to what I am going to order. The parameter is comes from the UI.
Here is the SQL MAP :
<select id="QueryBranch" resultClass="HashTable" parameterClass="HashTable">
SELECT BRANCH_CODE
,OFFICE_CODE
FROM BRANCH_MASTER
ORDER BY #SortExpr# ASC
</select>
#SortExpr# will be either BRANCH_CODE or OFFICE_CODE which is supplied from UI.
The above statements give me result but not in order that I want.
But, if I change into like this :
<select id="QueryBranch" resultClass="HashTable" parameterClass="HashTable">
SELECT BRANCH_CODE
,OFFICE_CODE
FROM BRANCH_MASTER
ORDER BY OFFICE_CODE ASC
</select>
It gives me the correct order of the records.
Am I missing something?? Help please....
Eka
Re: ORDER BY CLAUSE
Posted by Uwe Lesta <le...@sbs-softwaresysteme.de>.
Eka Gautama wrote:
> Hi Lesta,
>
> Thanks for the help and it works!!
>
> Just wondering, why my way was not working? Any reasons why?
The syntax of #SortExpr# make a substitution with the value of the property named by SortExpr.
The syntax of $SortExpr$ make a substitution with the value of SortExpr.
<snip>
--
Kind regards
Uwe
Lesta at SBS-Softwaresysteme.de
Re: ORDER BY CLAUSE
Posted by Eka Gautama <ek...@seatech.com>.
Hi Lesta,
Thanks for the help and it works!!
Just wondering, why my way was not working? Any reasons why?
Regards
Eka
----- Original Message -----
From: "Uwe Lesta" lesta@sbs-softwaresysteme.de
To: <us...@ibatis.apache.org>
Sent: Tuesday, August 08, 2006 7:21 PM
Subject: Re: ORDER BY CLAUSE
>
>
> Eka Gautama wrote:
>
>> HI guys,
>>
>> I am having problem currently. I have a very simple query with ORDER BY
>> clause, but I want to give parameter to what I am going to order. The
>> parameter is comes from the UI.
>>
>> Here is the SQL MAP :
>>
>> <select id="QueryBranch" resultClass="HashTable"
>> parameterClass="HashTable">
>> SELECT BRANCH_CODE ,OFFICE_CODE FROM BRANCH_MASTER
>> ORDER BY #SortExpr# ASC
>> </select>
>>
>> #SortExpr# will be either BRANCH_CODE or OFFICE_CODE which is supplied
>> from UI.
>>
>> The above statements give me result but not in order that I want. But, if
>> I change into like this :
>>
>> <select id="QueryBranch" resultClass="HashTable"
>> parameterClass="HashTable">
>> SELECT BRANCH_CODE ,OFFICE_CODE FROM BRANCH_MASTER
>> ORDER BY OFFICE_CODE ASC
>> </select>
>>
>>
>> It gives me the correct order of the records.
>
> try something like
>
> <dynamic prepend="ORDER BY ">
> <isNotEmpty property="SortField">
> $SortField$ $SortDirection$
> </isNotEmpty> </dynamic>
>
>
> --
>
> Kind regards
>
> Uwe
> Lesta at SBS-Softwaresysteme.de
>
Re: ORDER BY CLAUSE
Posted by Uwe Lesta <le...@sbs-softwaresysteme.de>.
Eka Gautama wrote:
> HI guys,
>
> I am having problem currently. I have a very simple query with ORDER BY clause, but I want to give parameter to what I am going to order. The parameter is comes from the UI.
>
> Here is the SQL MAP :
>
> <select id="QueryBranch" resultClass="HashTable" parameterClass="HashTable">
> SELECT BRANCH_CODE
> ,OFFICE_CODE
> FROM BRANCH_MASTER
> ORDER BY #SortExpr# ASC
> </select>
>
> #SortExpr# will be either BRANCH_CODE or OFFICE_CODE which is supplied from UI.
>
> The above statements give me result but not in order that I want.
>
> But, if I change into like this :
>
> <select id="QueryBranch" resultClass="HashTable" parameterClass="HashTable">
> SELECT BRANCH_CODE
> ,OFFICE_CODE
> FROM BRANCH_MASTER
> ORDER BY OFFICE_CODE ASC
> </select>
>
>
> It gives me the correct order of the records.
try something like
<dynamic prepend="ORDER BY ">
<isNotEmpty property="SortField">
$SortField$ $SortDirection$
</isNotEmpty>
</dynamic>
--
Kind regards
Uwe
Lesta at SBS-Softwaresysteme.de