# If Statement in Query Builder

**URL:** <https://forums.toadworld.com/t/if-statement-in-query-builder/39205>\
**Category:** Toad Data Point & Toad Intelligence Central\
**Created:** [March 14, 2017, 10:33am UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205 "2017-03-14T10:33:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Woomer](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@David\_Woomer](https://forums.toadworld.com/u/David_Woomer)\
**Post date:** [March 14, 2017, 10:33am UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/1 "2017-03-14T10:33:27Z")

</div>

I would like to add a calculated column in the query builder tool. I would like to switch the signs on amounts that have related a billing code of 2000 or greater. If the code is less than 2000 I want the sign to remain the same. Is there a way to do this via a calculated column?

Thanks.

---

<div class="post-metadata">

**Author:** ![armand\_charest\_31540](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@armand\_charest\_31540](https://forums.toadworld.com/u/armand_charest_31540)\
**Post date:** [March 14, 2017, 11:20am UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/2 "2017-03-14T11:20:04Z")

</div>

You need to make a calculate field.

Case  
When Billing\_Code \< 20000 Then My\_Amount\_Field  
Else ( My\_Amount\_Field \* -1 ) /\* will change the amount to a negative assuming the Amt is positive \*/  
End AMT

---

<div class="post-metadata">

**Author:** ![InfoMan](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/infoman/32/322_2.png) [@InfoMan](https://forums.toadworld.com/u/InfoMan)\
**Post date:** [March 14, 2017, 11:22am UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/3 "2017-03-14T11:22:27Z")

</div>

Yes, just create a calculated column (click the button with the sigma symbol to begin) and use a CASE statement. Something like:

case when table\_name.Billing\_Code \>= 2000 then ( table\_name.amount \* (-1) ) else table\_name.amount end

---

<div class="post-metadata">

**Author:** ![David\_Woomer](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@David\_Woomer](https://forums.toadworld.com/u/David_Woomer)\
**Post date:** [March 14, 2017, 11:40am UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/4 "2017-03-14T11:40:17Z")

</div>

Thanks…I don’t see a CASE function in the drop down box. Can I just type that statement into the field?

---

<div class="post-metadata">

**Author:** ![armand\_charest\_31540](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@armand\_charest\_31540](https://forums.toadworld.com/u/armand_charest_31540)\
**Post date:** [March 14, 2017, 11:42am UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/5 "2017-03-14T11:42:11Z")

</div>

Yes, you just have to write the code.

---

<div class="post-metadata">

**Author:** ![InfoMan](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/infoman/32/322_2.png) [@InfoMan](https://forums.toadworld.com/u/InfoMan)\
**Post date:** [March 14, 2017, 11:59am UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/6 "2017-03-14T11:59:04Z")

</div>

Yes, click the button to create the field, name it, click the plus button, then click the drop-down in the Field Definition area and type in the function. Choose a table to attach the calculated field to, and it will be in your query.

---

<div class="post-metadata">

**Author:** ![David\_Woomer](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@David\_Woomer](https://forums.toadworld.com/u/David_Woomer)\
**Post date:** [March 14, 2017, 12:22pm UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/7 "2017-03-14T12:22:30Z")

</div>

Thanks…I tried that still getting a lookup error ORA-00936: missing expression.

Here’s my code:

CASE WHEN LINE\_ITEM\_DETAIL.ILD\_LINE\_ITEM\_ID \>= **2000** THEN ( LINE\_ITEM\_DETAIL.ILD\_AMOUNT (\*- **1** )) ELSE LINE\_ITEM\_DETAIL.ILD\_AMOUNT END

---

<div class="post-metadata">

**Author:** ![armand\_charest\_31540](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@armand\_charest\_31540](https://forums.toadworld.com/u/armand_charest_31540)\
**Post date:** [March 14, 2017, 12:29pm UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/8 "2017-03-14T12:29:24Z")

</div>

Can you try this out?

CASE WHEN LINE\_ITEM\_DETAIL.ILD\_LINE\_ITEM\_ID \>= **2000**

THEN NVL(LINE\_ITEM\_DETAIL.ILD\_AMOUNT,0) \* -\*\*1 \*\*

ELSE NVL(LINE\_ITEM\_DETAIL.ILD\_AMOUNT,0)

END MyFieldName

---

<div class="post-metadata">

**Author:** ![David\_Woomer](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@David\_Woomer](https://forums.toadworld.com/u/David_Woomer)\
**Post date:** [March 14, 2017, 1:15pm UTC](https://forums.toadworld.com/t/if-statement-in-query-builder/39205/9 "2017-03-14T13:15:12Z")

</div>

Thank you both very much. That worked! I appreciate it!
