IN operator in iBatis

Another confusion will occur while working with iBatis , when we need to do something like

where id in (100,101,102)

We can simply do it as like this.

where r.status = ‘A’
<dynamic >
<isNotNull property=”Clients”>
and c.id
<iterate property=”Clients” open=”IN (” close=”)” conjunction=”,”>
#Clients[]#
</iterate>
</isNotNull>
<isNotNull property=”SMT”>
and t.smt_id
<iterate property=”SMT” open=”IN (” close=”)” conjunction=”,”>
#SMT[]#
</iterate>
</isNotNull>
</dynamic>

where SMT and Clients are lists, which can be any lists,  that I put into the parameter map(here am passing java.util.HashMap as parameter map).

Advertisements

Tags: , , , , ,

2 Responses to “IN operator in iBatis”

  1. ibatis_beg Says:

    Hi I tried this in my code, but it does not return any results, I ran the same sql on my db n it does return atleast 2 records. Could you please help. Here is my code

    SELECT distinct
    P_NPI_NUM FROM P_PROV_TB PRTB JOIN P_NTWRK_TB NTTB ON PRTB.P_ID = NTTB.P_ID WHERE NTTB.R_HLTH_PLN_ID IN (1,2) AND PRTB.P_NPI_NUM IN

    #npiList[]#

    created a hashmap (where npi is List

    Map paramMap = new HashMap();
    paramMap.put(“npiList”, npi);

    passed this paramMap into the queryForList call.

    • Anoop Says:

      Hi,

      I am not seeing any problem by just seeing that. Could you please send me the sqlmap file as well as the code snippet where you are calling the query. probably then I could make some assumptions.

      Thanks,
      PK

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: