sqlgoogle-sheetsgoogle-sheets-formulagoogle-query-languagenegate

Google sheets - Query + Importrange WHERE Clause doesn't accept AND for a second condition


I'm trying to pull a column of data from a file if two conditions are met.

If I write the formula with one condition works perfectly =QUERY(IMPORTRANGE("url", "PIP!A2:S"), "SELECT Col2 WHERE Col3 = 'Schedule Change'")

But if I add a second condition with an AND clause it breaks =QUERY(IMPORTRANGE("url", "PIP!A2:S"), "SELECT Col2 WHERE Col3 = 'Schedule Change' AND Col8 IS NOT 'Closed'")

This is the error Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "Col8 "" at line 1, column 47. Was expecting one of: "(" ... "(" ...

Can't share the url cause is data from my company, but if you could help me sort this one out

Angelo


Solution

  • only is not null is supported otherwise you need to do it like this:

    =QUERY(IMPORTRANGE("url", "PIP!A2:S"), 
     "select Col2 
      where Col3 = 'Schedule Change' 
        and not Col8 = 'Closed'")
    

    or:

    =QUERY(IMPORTRANGE("url", "PIP!A2:S"), 
     "select Col2 
      where Col3 = 'Schedule Change' 
        and Col8 <> 'Closed'")
    

    or:

    =QUERY(IMPORTRANGE("url", "PIP!A2:S"), 
     "select Col2 
      where Col3 = 'Schedule Change' 
        and Col8 != 'Closed'")