How To Solve “SQL Truncation” using SQL
Jul 15, 2023
I recently wrote about how to resolve a SQL Truncation error with Excel.
Here’s how you can solve it with SQL.
The Code
SELECT
MAX(LEN_ID) AS MAX_ID
, MAX(LEN_EmployeeName) AS MAX_EmployeeName
FROM (
SELECT
LEN(ID) AS LEN_ID
, LEN(EmployeeName) AS LEN_EmployeeName
FROM tblEmployeeList
) AS qryGetMax
The Explanation
- Query the necessary fields from the table(s) using the LEN function to find the length of each value
- Put that inside another query, and use the MAX function to get the maximum length of every instance
- Compare the results one-by-one to the table structure to see which field(s) in the SQL query results exceed the maximum number of characters allowed in the table.