Retrieve the maximum length of a VARCHAR column in SQL Server

前端 未结 10 1658
时光说笑
时光说笑 2021-01-30 10:18

I want to find the longest VARCHAR in a specific column of a SQL Server table.

Here\'s an example:

ID = INT IDENTITY
DESC = VARCHAR(5000)

I         


        
10条回答
  •  不思量自难忘°
    2021-01-30 10:47

    Watch out!! If there's spaces they will not be considered by the LEN method in T-SQL. Don't let this trick you and use

    select max(datalength(Desc)) from table_name
    

提交回复
热议问题