0

Need help with following dynamic query:

if country==null OR country != (spain || Peru)
select * from emp where country NOT IN (spain,Peru)
else
select * from emp where country=#{country}

I tried something like this but its not helping:

<when test="country ==null" or country !='spain' or country != 'Peru'">
            AND country NOT IN ('spain','peru')
            </when>
            <otherwise>
            AND country=#{country}
 </otherwise>

Always generate NOT IN even if country=us

3 Answers 3

1

try this test="country == null or country != 'spain' or country != 'UK' "

Sign up to request clarification or add additional context in comments.

1 Comment

always generating NOT IN
0

Use double quotation to string.

<when test='country == null or !country.equals("spain") or !country.equals("uk")'>
        AND country NOT IN ('spain','uk')
        </when>
        <otherwise>
        AND country=#{country}
 </otherwise>

Comments

0
<when test="country !='spain' and country != 'uk'">

wrong condition, expected and instead of or

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.