Fixing 'Unable to parse query string for Function QUERY parameter 2' in Google Sheets

intermediate๐Ÿ“— Google Sheets2026-03-29| Google Sheets (web-based application, accessible via any modern web browser on Windows, macOS, Linux, Chrome OS, Android, iOS)

Error Message

Unable to parse query string for Function QUERY parameter 2
#google-sheets#query#function#syntax

TL;DR Quick Fix

This error almost always means there's a problem with the syntax of the query string itself โ€“ the second argument to your QUERY function.

  • Check Column References: Are you using A, B, C (if your data range starts at column A) or Col1, Col2, Col3 (if your data range is a subset, e.g., B1:D100)?
  • String Literals: Make sure all text values in your WHERE clause conditions are enclosed in single quotes ('text') and the entire query string is in double quotes ("SELECT ... 'text'").
  • Date Literals: Dates need a specific format: DATE 'YYYY-MM-DD'.
  • Escaping Quotes: If your string literal itself contains single quotes, you'll need to double them up (e.g., 'O''Malley').
  • Missing Keywords: Ensure you have SELECT at the beginning of your query.

Detailed Root Cause

The QUERY function in Google Sheets is incredibly powerful, essentially bringing SQL-like capabilities to your spreadsheets. The error message Unable to parse query string for Function QUERY parameter 2 tells us that the interpreter for the Google Visualization API Query Language couldn't understand what you're asking it to do.

Parameter 2 of the QUERY function is the actual query string (e.g., "SELECT A, B WHERE C > 10"). This isn't an error about your data types in the sheet, or the range you've selected for the first parameter. It's purely about the grammar and vocabulary used within the query string itself.

Think of it like trying to speak a foreign language with incorrect sentence structure or misused words โ€“ the listener (Google Sheets) simply can't parse your intent. Common reasons for this parsing failure include:

  • Incorrect Column Identifiers: Mixing A, B, C with Col1, Col2, Col3 inappropriately.
  • Improper Quoting for String Literals: Text values in WHERE clauses must be single-quoted.
  • Incorrect Date/Time Literals: Dates and times have a specific syntax.
  • Missing or Misplaced Keywords/Clauses: Forgetting SELECT, WHERE, GROUP BY, etc., or putting them in the wrong order.
  • Typos or Invalid Syntax: Simple mistakes in keywords or function names within the query string.
  • Unescaped Special Characters: Especially single quotes within string literals.

Fix Approaches

Let's break down the common pitfalls and how to fix them.

1. Column References: A, B, C vs. Col1, Col2, Col3

This is a very frequent source of the error. The way you refer to columns depends on the range you provide to QUERY.

  • If your data range for QUERY starts at column A and covers full columns (e.g., A:D, A1:D100), you should refer to columns using their letter names: A, B, C.
  • If your data range is a subset of columns that doesn't start at A (e.g., B1:D100), or if you're using a named range that represents a subset, you must use Col1, Col2, Col3 to refer to the relative column numbers within your selected range. Col1 would be the first column of your selected range, Col2 the second, and so on.

Incorrect Example (using column letters for a subset range):

=QUERY(B1:D100, "SELECT B, C WHERE D > 10")

Why it's wrong: The range B1:D100 means that column B is now the first column of the data QUERY sees. So, B should be Col1, C should be Col2, and D should be Col3.

Corrected Example:

=QUERY(B1:D100, "SELECT Col1, Col2 WHERE Col3 > 10")

Another Incorrect Example (common with IMPORTRANGE):

=QUERY(IMPORTRANGE("spreadsheet_url", "Sheet1!C:Z"), "SELECT A, B WHERE C = 'Status'")

Why it's wrong: IMPORTRANGE here is bringing in data starting from column C. So, A, B, C are no longer valid column references within the imported range. C would be Col1, D would be Col2, etc.

Corrected Example:

=QUERY(IMPORTRANGE("spreadsheet_url", "Sheet1!C:Z"), "SELECT Col1, Col2 WHERE Col3 = 'Status'")

2. String Literals and Quoting

All text values in your WHERE clause (or other clauses expecting text) must be enclosed in single quotes ('). The entire query string itself is enclosed in double quotes (").

Incorrect Example:

=QUERY(A:C, "SELECT A, B WHERE C = Active")

Why it's wrong: Active is treated as a column name or an invalid keyword because it's not quoted.

Corrected Example:

=QUERY(A:C, "SELECT A, B WHERE C = 'Active'")

Escaping Single Quotes within a String:

If the string you're searching for contains a single quote (e.g., "O'Malley"), you need to escape it by doubling it up.

Incorrect Example:

=QUERY(A:B, "SELECT A WHERE B = 'O'Malley'")

Why it's wrong: The parser sees 'O' as a string, then Malley' as an unquoted, invalid part.

Corrected Example:

=QUERY(A:B, "SELECT A WHERE B = 'O''Malley'")

3. Date and Time Literals

Dates and times have a specific syntax in QUERY. Dates must be in the format DATE 'YYYY-MM-DD'. Times require TIME 'HH:MM:SS' and datetimes DATETIME 'YYYY-MM-DD HH:MM:SS'.

Incorrect Example:

=QUERY(A:B, "SELECT A WHERE B > '2023-01-01'")

Why it's wrong: QUERY needs the DATE keyword to understand '2023-01-01' as a date, not just a string.

Corrected Example:

=QUERY(A:B, "SELECT A WHERE B > DATE '2023-01-01'")

4. Missing Keywords or Invalid Syntax

  • Always start your query string with SELECT.
  • Ensure clauses are in the correct order: SELECT, WHERE, GROUP BY, PIVOT, ORDER BY, LIMIT, OFFSET, LABEL, FORMAT, OPTIONS.
  • Check for typos in keywords (e.g., WHER instead of WHERE).

Incorrect Example:

=QUERY(A:B, "A, B WHERE C = 'Done'")

Why it's wrong: Missing the SELECT keyword.

Corrected Example:

=QUERY(A:C, "SELECT A, B WHERE C = 'Done'")

5. Using Cell References to Build Queries

When you want parts of your query to be dynamic (e.g., filtering based on a value in cell D1), you need to concatenate the query string parts using the & operator. Pay close attention to quotes!

Suppose cell D1 contains the status "Pending".

Incorrect Example:

=QUERY(A:C, "SELECT A, B WHERE C = D1")

Why it's wrong: D1 is treated as a literal string "D1" within the query, not a cell reference.

Corrected Example (for text in D1):

=QUERY(A:C, "SELECT A, B WHERE C = '" & D1 & "'")

Explanation:

  • "SELECT A, B WHERE C = '": Starts the string, includes the opening single quote for the value.
  • & D1 &: Concatenates the value of cell D1.
  • "'": Closes the single quote for the value and closes the double quote for the entire query string.

Corrected Example (for a number in D1):

=QUERY(A:C, "SELECT A, B WHERE C = " & D1)

Notice no single quotes around D1 for numbers.

Corrected Example (for a date in D1, e.g., 2023-01-15):

=QUERY(A:B, "SELECT A WHERE B > DATE '" & TEXT(D1, "yyyy-mm-dd") & "'")

Explanation: We use TEXT(D1, "yyyy-mm-dd") to ensure D1 is formatted correctly as a string for the DATE literal.

Debugging Strategy

For complex queries, break them down:

  • Start simple: Begin with just SELECT Col1, Col2 to ensure your column references are correct.
  • Add one clause at a time: Introduce WHERE next, then GROUP BY, ORDER BY, etc. Test after each addition.
  • Inspect the full query string: Instead of putting the query directly into QUERY, build it in a separate cell (e.g., D2) using concatenation, then reference D2 in your QUERY function: =QUERY(A:C, D2). This lets you visually inspect the exact string QUERY is trying to parse.

Example for inspecting the query string:

// In cell D2, construct your query string:
="SELECT A, B WHERE C = '" & E1 & "' ORDER BY A DESC"

// In cell F1, reference the constructed query string:
=QUERY(A:C, D2)

This way, if F1 errors, you can see exactly what string D2 produced and debug it.

Verification Steps

  • Check the formula output: Once you've applied a fix, the QUERY function should now execute without the "Unable to parse query string" error.
  • Validate the data: Ensure the results returned by the QUERY function are what you expect. Sometimes a syntax fix might make the query run, but it might not be filtering or selecting correctly if there are subtle logical errors remaining (e.g., searching for 'Active' when the sheet actually contains 'active').
  • Test edge cases: If your query uses cell references, try changing the values in those reference cells to ensure the query adapts correctly without breaking.

Further Reading

  • Search for "Google Sheets QUERY function" in Google's official documentation for a comprehensive guide.
  • Explore the "Google Visualization API Query Language Reference" for the underlying language specification.

Related Error Notes