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

Troubleshooting Guide: SQL Server Error 242 – Out-of-Range Data Type Conversion

Why This Error Happens

Error 242 occurs when SQL Server attempts to implicitly or explicitly convert a value from one data type to another, but the resulting value falls outside the permissible range of the target data type. This is commonly seen when converting large or improperly formatted strings into datetime, smalldatetime, or numeric types like int and smallint. The root cause is almost always a data integrity or application-logic issue rather than a SQL Server configuration or installation problem, meaning the source data does not conform to the boundaries expected by the destination column or variable.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query and Data

  • Enable SQL Server Profiler or Extended Events on the instance to capture the exact query causing Error 242.
  • Check the SQL Server error log located at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG on Windows Server 2025 for the timestamp and statement context.
  • Isolate the specific INSERT, UPDATE, or SELECT statement referenced in the error stack.

Step 2: Validate Source Data Ranges

  • Run a diagnostic query to find out-of-range values before conversion, for example:
  • SELECT * FROM SourceTable WHERE TRY_CONVERT(smalldatetime, DateColumn) IS NULL AND DateColumn IS NOT NULL;
  • Confirm whether the source column contains dates outside the smalldatetime range (January 1, 1900, through June 6, 2079) or numeric values exceeding smallint/int boundaries.

Step 3: Correct the Data Type Mismatch

  • Modify the destination column definition to use a wider data type, such as changing smalldatetime to datetime2 via SQL Server Management Studio (SSMS) or a ALTER TABLE script.
  • Alternatively, use TRY_CONVERT() or TRY_CAST() in the query logic to gracefully handle invalid values instead of throwing a hard error.
  • Update ETL packages (SSIS) or application connection strings if truncation settings are causing improper type coercion during data load.

Step 4: Patch and Restart the SQL Service

  • Ensure SQL Server 2025 is updated with the latest Cumulative Update (CU) via Microsoft Update or the SQL Server Installation Center, as type-handling bugs are occasionally patched.
  • Restart the SQL Server service using Services.msc or run net stop MSSQLSERVER && net start MSSQLSERVER in an elevated Command Prompt on Windows Server 2025.

Alternative or Verification Steps

  • Re-run the original failing transaction in SSMS; if it completes without throwing Error 242, the data range issue has been resolved.
  • If the error persists intermittently, implement a CHECK CONSTRAINT on the table to proactively reject out-of-range values before they enter the database, preventing future conversion failures at the application layer.