How to fix Error 2336 on Windows Server 2025 / Windows 11

Why This Error Happens

Error 2336 is thrown by the SQL Server parser (most commonly surfaced through sp_execute_external_script, PolyBase external table definitions, or dynamic T-SQL batches that embed Python/R snippets) when it encounters a numeric literal beginning with a leading zero — such as 0192 — and interprets it as an octal number. Since valid octal digits only range from 0–7, any 8 or 9 in that literal causes the parser to reject it outright. This typically stems from improperly sanitized input strings, copy-pasted configuration values, or auto-generated scripts that preserve zero-padded numbers (e.g., zip codes, IDs, or timestamps) without quoting them as strings.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Script or Query

  • Check the SQL Server Error Log (Management > SQL Server Logs) or Event Viewer under Applications and Services Logs > Microsoft > SQL Server for the exact batch or script triggering Error 2336.
  • If using sp_execute_external_script, isolate the Python/R block and look for zero-padded numeric values (e.g., area_code = 0752).

Step 2: Correct the Numeric Literal Formatting

  • Wrap the problematic value in quotes to treat it as a string instead of a number: area_code = '0752'.
  • If the value must remain numeric, strip the leading zero or explicitly cast it: CAST('0752' AS INT) in T-SQL, or int("0752") in Python (never leave it as a bare literal).

Step 3: Update External Script Language Extensions

  • Open SQL Server Configuration Manager and confirm the Machine Learning Services / Language Extensions (Python/R) components are updated to the build compatible with SQL Server 2025.
  • Run EXEC sp_configure 'external scripts enabled', 1; RECONFIGURE; to ensure the feature is properly reloaded after any patch.
  • Reinstall or repair the language extension via Add or Remove Programs > Microsoft SQL Server 2025 > Language Extensions if the parser behavior seems inconsistent after updates.

Step 4: Validate Dynamic SQL Generation Logic

  • If the query is dynamically built (e.g., via an ETL tool or ORM), inspect the generation logic in your application code (C#, PowerShell, or SSIS script tasks) to ensure numeric strings aren’t concatenated without proper escaping.
  • Add explicit string delimiters around any field that may contain leading zeros before it reaches the SQL Server parser.

Alternative or Verification Steps

  • Re-run the exact script or stored procedure in SQL Server Management Studio (SSMS) on Windows 11/Windows Server 2025 and confirm Error 2336 no longer appears in the Messages pane.
  • As a quick alternative, temporarily disable octal interpretation by converting all numeric literals to explicit VARCHAR or INT casts throughout the script, then re-enable external scripting (sp_configure 'external scripts enabled') to confirm stability.