# Using Conditional Statement in an SQL Query?

**URL:** <https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [July 25, 2025, 7:23pm UTC](https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963 "2025-07-25T19:23:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcamp1](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@dcamp1](https://forum.inductiveautomation.com/u/dcamp1)\
**Post date:** [July 25, 2025, 7:23pm UTC](https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963/1 "2025-07-25T19:23:15Z")

</div>

Hello: I can't figure this out and to be honest I don't know if it can even be done?

Here's what I need:

I want to query a Table in my database (I'm running Microsoft SQL Server) the TABLE name is carbondata.

The column name is AshleyVfd\_Hz ( this is a "Float DataType" it hold data with a decimal point)  
I want to replace the column name to BlowerStatus in my "ReturnData". (Note: BlowerStatus needs to be a boolean datatype)

My conditions is simple:  
If AshleyVfd\_Hz \> 0 Then BlowerStatus = 1  
Else  
BlowerStatus = 0

Can someone help me with my "QUERY"?

Thanks

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [July 25, 2025, 7:27pm UTC](https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963/2 "2025-07-25T19:27:50Z")

</div>

I think you want a [`CASE` expression](https://www.w3schools.com/sql/sql_case.asp)

---

<div class="post-metadata">

**Author:** ![dcamp1](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@dcamp1](https://forum.inductiveautomation.com/u/dcamp1)\
**Post date:** [July 25, 2025, 7:44pm UTC](https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963/3 "2025-07-25T19:44:49Z")

</div>

I have tried both ways Case and If(IIF) I need an example of the complete query, that seems to be my problem, I can't come up with the correct QUERY FORMAT.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [July 25, 2025, 7:46pm UTC](https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963/4 "2025-07-25T19:46:41Z")

</div>

The link shows an example:

```python
SELECT OrderID, Quantity,
CASE
    WHEN Quantity > 30 THEN 'The quantity is greater than 30'
    WHEN Quantity = 30 THEN 'The quantity is 30'
    ELSE 'The quantity is under 30'
END AS QuantityText
FROM OrderDetails;

```

Replace the table and column names with your table/column names. You may need to remove some columns from the `SELECT` statement as you may not have as many columns. (For example `Quantity` would be replaced by `AshleyVfd_Hz`)

Also, show some examples of SQL statements that you have tried that have not worked. Make sure to post them as [preformatted text](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [July 25, 2025, 7:50pm UTC](https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963/5 "2025-07-25T19:50:48Z")

</div>

```python
SELECT 
CASE
    WHEN AshleyVfd_Hz > 0 THEN 1
    ELSE 0
END AS BlowerStatus 
FROM carbondata

```

---

<div class="post-metadata">

**Author:** ![robertm](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@robertm](https://forum.inductiveautomation.com/u/robertm)\
**Post date:** [July 25, 2025, 7:52pm UTC](https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963/6 "2025-07-25T19:52:19Z")

</div>

Would a simple SELECT work?

SELECT  
Ashley\_VFD\_Hz,  
(Ashley\_VFD\_Hz \>0) AS BlowerStatus  
From Carbondata

---

<div class="post-metadata">

**Author:** ![dcamp1](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@dcamp1](https://forum.inductiveautomation.com/u/dcamp1)\
**Post date:** [July 25, 2025, 7:59pm UTC](https://forum.inductiveautomation.com/t/using-conditional-statement-in-an-sql-query/108963/7 "2025-07-25T19:59:35Z")

</div>

Thanks, That is exactly what I needed. Works perfectly.
