Using Conditional Statement in an SQL Query?

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

I think you want a CASE expression

1 Like

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.

The link shows an example:

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.

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

Would a simple SELECT work?

SELECT
Ashley_VFD_Hz,
(Ashley_VFD_Hz >0) AS BlowerStatus
From Carbondata

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