# Sql where condition with case is not converting to bool query

**URL:** <https://discuss.elastic.co/t/sql-where-condition-with-case-is-not-converting-to-bool-query/322071>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [December 28, 2022, 6:47am UTC](https://discuss.elastic.co/t/sql-where-condition-with-case-is-not-converting-to-bool-query/322071 "2022-12-28T06:47:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alok.Singh](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@Alok.Singh](https://discuss.elastic.co/u/Alok.Singh)\
**Post date:** [December 28, 2022, 6:47am UTC](https://discuss.elastic.co/t/sql-where-condition-with-case-is-not-converting-to-bool-query/322071/1 "2022-12-28T06:47:49Z")

</div>

Hello @elastic

I have a view called V1, I want to filter data based on role. If role is 1 or 2 then role can see all record else for other role they can see only those record which is assign to them.  
sql query:

```sql
select * from V1 
where case when role in (1,2) 
then 1=1 
else role = ${role}

```

I want to convert above sql query to bool query.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 25, 2023, 6:47am UTC](https://discuss.elastic.co/t/sql-where-condition-with-case-is-not-converting-to-bool-query/322071/2 "2023-01-25T06:47:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
