Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 带前导和尾随空格的tsql LTRIM和LEN_Sql Server_Tsql - Fatal编程技术网

Sql server 带前导和尾随空格的tsql LTRIM和LEN

Sql server 带前导和尾随空格的tsql LTRIM和LEN,sql-server,tsql,Sql Server,Tsql,我的字符串包含前导空格和尾随空格(见下文) 当我应用LRTIM函数时,它似乎起作用。接下来,当我将带有LEN函数的LTRIM函数嵌套到字符串中时,似乎长度为off 1(即原始字符串的长度为16,LTRIM从字符串中删除了一(1)个前导空格,因此我希望LEN返回的长度为15,而不是14)。有什么解释吗 SELECT ' This is a test ' AS origStr ,LEN(' This is a test ') AS origStrLen ,'[' + LTRIM(' This is

我的字符串包含前导空格和尾随空格(见下文)

当我应用LRTIM函数时,它似乎起作用。接下来,当我将带有LEN函数的LTRIM函数嵌套到字符串中时,似乎长度为off 1(即原始字符串的长度为16,LTRIM从字符串中删除了一(1)个前导空格,因此我希望LEN返回的长度为15,而不是14)。有什么解释吗

SELECT
 ' This is a test ' AS origStr
,LEN(' This is a test ') AS origStrLen
,'[' + LTRIM(' This is a test ') + ']' AS ltrimStr
,LEN(LTRIM(' This is a test ')) AS strLtrimLen
;
结果:

This is a test | 16 | [This is a test ] | 14 |
这是因为len()不在字符串空格后计数

LEN(LTRIM(' This is a test ')) has one space before and one space after string. 
例如:
选择LEN('TEXT')
返回--->4

很抱歉重新发布了此特定问题。感谢您提供解释此问题的链接。我读了关于数据长度和长度的比较。