最新消息:

SQL Server 获取字符串的长度,查询小于某个字符数的数据

编程 eben 3299浏览

对于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个位置。

 

 

转载请注明:落伍老站长 » SQL Server 获取字符串的长度,查询小于某个字符数的数据