Toad World® Forums

Toad Data Point - Local Storage - MySQL - Select nested if statement

SELECT DISTINCT

IF(CAL_QUAL.CAL_BASE_MATRIX.Blanks_Coil = “Coil”,

IF(ISNULL(Subquery_1.TS_Result_Type), ‘NO’, Subquery_1.TS_Result_Type),

Subquery_1.TS_Result_Type) as Subquery_1.TS_Result_Type

From …

WHERE (Subquery_1.Result_Type <> ‘NO’)

I’m having trouble with the syntax, I believe. This syntax is so confusing. Sometimes you use parenthesis. Sometimes you don’t. I’m used to VBA where the syntax is the same for everything, and the script flows sequentially like a thought process. I simply want to:

  1. Check the values of a column called “Blanks_Coil”. If the value of “Blanks_Coil” = “Coil” Then

  2. Check a column called “TS_Result_Type”. If the value of “TS_Result_Type” is null, set the value of “TS_Result_Type” = “NO”, Else leave the current value

  3. Else if the value of “Blanks_Coil” <> “Coil”, leave the current value of “TS_Result_Type”

  4. Once that is done, I only want to include values Where “TS_Result_Type” <> “NO”

Try:

IF(CAL_QUAL.CAL_BASE_MATRIX.Blanks_Coil = “Coil”, IF(TS_Result_Type is null, ‘NO’,TS_Result_Type),TS_Result_Type)

ISNULL Syntax:

If expr is NULL, ISNULL() returns 1, otherwise it returns 0.

mysql> SELECT ISNULL(1+1);

-> 0

mysql> SELECT ISNULL(1/0);

-> 1