sql server2005版本中,len函数计算了字符串末尾的空格的长度,以下是测试脚本:
print @@version
declare @v varchar(max)
set @v = 'hp, '
print @v + 't'
print len(@v)
print left(@v,len(@v) - 1) + 't'
2005的执行结果:
Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
hp, t
4
hp,t --截取掉的是末尾的空格
2008的输出结果:
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
Jun 28 2012 08:36:30
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
hp, t
3
hpt --截取掉的是末尾的,
2012的输出结果:
Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64)
Oct 19 2012 13:38:57
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
hp, t
3
hpt --截取掉的是末尾的,