Ice
Ice

Reputation: 314

Querydsl case when in where clause

Am looking for example on use case when condition in where clause on querydsl.

SELECT column1, column2 FROM viewWhatever WHERE CASE WHEN column1 == 'b' THEN account_location = ? WHEN column1 =='m' THEN location_area = ?

I just recently start using querydsl I can't figure out how to represent above query in querydsl case builder expression. I found examples for use in select clause but couldn't find much for use in where clause.

Upvotes: 0

Views: 2208

Answers (1)

Alan Hay
Alan Hay

Reputation: 23226

Do you really need a CASE statement?

SELECT 
   column1, column2 
FROM 
   viewWhatever 
WHERE 
   (column1 == 'b' AND account_location = ?)
OR
   (column1 =='m' AND location_area = ?)

Can obviously be easily represented in QueryDSL.

Upvotes: 1

Related Questions