sqlsql-servert-sqldatalength

SQL Server - Truncate Using DATALENGTH


Is there a way to truncate an nvarchar using DATALENGTH? I am trying to create an index on a column, but an index only accepts a maximum of 900 bytes. I have rows that consist of 1000+ bytes. I would like to truncate these rows and only accept the first n characters <= 900 bytes.


Solution

  • Can be this sql useful, Just update the table for that column.

    Update Table
    Set Column = Left(Ltrim(Column),900)