SELECT * FROM your_table WHERE LEN(your_column) < desired_length;
--查询字符串长度
select DATALENGTH('menghaipeng')
select LEN('menghaipeng')
--条件查询
--查询id长度小于23的数据
select distinct id,DATALENGTH(id) From table1
--where DATALENGTH(id)<23
where LEN(id)<23
对于char nvarchar(10) 等类型可用 Len函数;
但对于text,ntext,image 等类型的字段,len函数不管用,必须用DataLength函数。
比如需要查询IAH04字段字符数小于15的数据
select * from IAH1 where Len(IAH04) < 15
SQL server数据库计算字符长度用datalength(函数),写法如下:
select * from xxx where datalength(xx)=4,
表示数据库里字符个数等于2个,依次类推,找出长度为10个字符串的话,datalength(xx)=20
不知道是不是每个字符都占2个位置。