Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1035: Incorrect Syntax Explained

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1035 ("Incorrect syntax near...") means the query parser hit a token it did not expect at that position, so the statement was rejected before it ran. The fix is almost always in the text of the query itself: a missing comma, a reserved word used as an identifier, a stray bracket, or a clause in the wrong order. This guide walks through locating the exact character, correcting the syntax, and preventing the same mistake from recurring in stored procedures and application code.

What You'll Need

  • Access to SQL Server Management Studio (SSMS), Azure Data Studio, or whichever client you use to run queries.
  • The exact text of the failing statement, including the line number reported by the error.
  • Permission to view the object definition if the error comes from a stored procedure, view, or trigger (for example, VIEW DEFINITION or membership in a role that has it).
  • A non-production copy of the database where you can test the corrected statement safely.

Step-by-Step

  1. Read the full error message, not just the code. Error 1035 is usually followed by the offending token and a line number, for example "Incorrect syntax near 'FROM'." The token after "near" is the first thing SQL Server could not parse, which is often one position after the real mistake. Write down both the token and the line number before changing anything.
  2. Open the query in a client that shows line numbers. In SSMS, turn on line numbers from the Query menu or the status bar; in Azure Data Studio the editor shows them by default. Jump to the reported line and look at the token immediately before it as well as the token itself.
  3. Check the statement order. The clauses of a SELECT must appear in this order: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY. A common cause of error 1035 is placing WHERE after GROUP BY, or writing ORDER BY before WHERE. Rewrite the statement so the clauses follow the required sequence.
  4. Look for missing or extra commas. In a column list or a VALUES list, a missing comma between two items produces "Incorrect syntax near" the second item. An extra trailing comma before FROM or before a closing parenthesis produces the same message near the keyword that follows. Count the items and the commas; they should match.
  5. Check for reserved words used as names. If a column, table, or alias is called something like Order, User, Key, or Desc, SQL Server may read it as a keyword. Wrap the identifier in square brackets, for example [Order], or use double quotes if QUOTED_IDENTIFIER is on. Do not rename the object just to fix the query.
  6. Balance parentheses and quotes. An unclosed parenthesis, a missing closing quote on a string literal, or a bracket that opens but never closes will shift the parser's expectations and surface as error 1035 further along. Use your editor's bracket matching, or paste the statement into a formatter that highlights unbalanced pairs.
  7. Check the object type you are altering. If the error appears when running ALTER PROCEDURE, CREATE VIEW, or CREATE TRIGGER, confirm the batch starts with the correct keyword and that GO separators are placed correctly. A missing GO between statements can merge two batches and confuse the parser.
  8. Isolate the failing fragment. Comment out sections of the query with -- or /* */ and run progressively smaller pieces until the error disappears. The last fragment you removed contains the problem. This is faster than rereading a long statement.
  9. Correct the text and re-run in a test database. Apply the fix, run the statement against a non-production copy first, and confirm it returns the expected rows. Only then run it against production.
  10. If the error comes from application code, fix it at the source. Search the codebase for the exact statement or the stored procedure name. Parameterize the query rather than concatenating strings, because string concatenation is a frequent source of missing quotes and stray commas. Redeploy the corrected code and retest.

Common Mistakes

  • Fixing the token named in the error instead of the one before it. The parser reports where it gave up, which is usually one token after the actual mistake. Always inspect the preceding token.
  • Assuming the error is a permissions or connection problem. Error 1035 is purely a parsing failure; it happens before permissions are evaluated. If permissions were the issue you would see a different error number.
  • Editing the production stored procedure directly. Test the corrected definition in a development copy first, then apply it through your normal deployment process.
  • Renaming columns to avoid reserved words. Bracket the identifier in the query instead; renaming breaks other code that references the column.
  • Ignoring the line number. The line number in the message points to the batch as sent, which may differ from the line numbers in your editor if the client adds or strips text. Compare the statement text, not just the line count.

Tips

  • Use a SQL formatter or linter in your editor; most catch unbalanced parentheses and clause-order problems before you run the query.
  • Keep one statement per batch and use GO deliberately, so a syntax error in one statement does not obscure the rest.
  • When writing dynamic SQL, build the string in a variable and print it before executing, so you can read the exact text the server will parse.
  • Store the corrected query in version control alongside the fix, so the same mistake is easier to spot next time.
  • Prefer bracketed identifiers for any name that could collide with a keyword, even if it currently parses; this makes the query resilient to future reserved-word additions.

Troubleshooting

If the error persists after you have checked commas, brackets, quotes, and clause order, work through the following in order. First, copy the exact statement into a fresh query window and run it alone; text hidden in a larger script or a batch separator can change how it parses. Second, check the database compatibility level, because syntax accepted at one level may be rejected at another; you can view it in the database properties. Third, if the failing statement is inside a stored procedure, script the procedure's definition and read the whole body, since the error may be in a section you did not write. Fourth, if the statement is generated by an application, capture the exact SQL text the application sends (many drivers log it) and compare it with what you expect; placeholders or missing quotes often appear there. Fifth, if you still cannot see the problem, paste the statement into a formatter that reports the first invalid token, which usually matches the server's complaint. If none of these resolves it, reduce the statement to the smallest version that still fails and compare it line by line with a known-good query against the same table.

Frequently Asked Questions

What does SQL Server error 1035 mean?

It means the parser encountered a token it could not accept at that point in the statement. The statement was not executed, so no data was changed.

Is error 1035 the same as a syntax error?

Yes. It is one of SQL Server's syntax error numbers; the message text "Incorrect syntax near" is the reliable clue, and the number can vary by version and context.

Why does the error point to a word that looks correct?

The parser reports where it stopped, which is usually the token after the real mistake. Check the token immediately before the one named in the message.

Can error 1035 be caused by a reserved word?

Yes. Using a keyword such as Order or User as a column or table name without brackets can trigger it. Bracket the identifier to resolve it.

Does error 1035 affect data?

No. The statement fails at parse time, before execution, so no rows are inserted, updated, or deleted.

How do I find the line with the problem in a long script?

Use the line number in the error message, then comment out sections of the script and re-run until the error disappears. The last removed section contains the fault.