Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
String 如何使用t-sql获取字符串中的第二个单词?_String_Tsql_Parsing_Split_Charindex - Fatal编程技术网

String 如何使用t-sql获取字符串中的第二个单词?

String 如何使用t-sql获取字符串中的第二个单词?,string,tsql,parsing,split,charindex,String,Tsql,Parsing,Split,Charindex,我想从第一个和第三个空格之间的字符串或短语中提取第二个单词 比如说 “波音公司” 我想要“波音” dbfiddle只是使用一点XML的另一个选项 范例 declare @sentence nvarchar(264); set @sentence = 'The Boeing Corporation'; select ltrim(substring(@sentence,charindex(' ',@sentence), CHARINDEX(' ',ltrim(SUBSTRING(@sentenc

我想从第一个和第三个空格之间的字符串或短语中提取第二个单词

比如说

“波音公司”

我想要“波音”


dbfiddle

只是使用一点XML的另一个选项

范例

declare @sentence nvarchar(264);

set @sentence = 'The Boeing Corporation';

select ltrim(substring(@sentence,charindex(' ',@sentence), CHARINDEX(' ',ltrim(SUBSTRING(@sentence,charindex(' ',@sentence),LEN(@sentence)-charindex(' ',@sentence)))) ))
| (No column name) | | :--------------- | | Boeing |
Declare @YourTable table (SomeCol varchar(500))
Insert Into @YourTable values
('The Boeing Corporation')

Select SomeCol
      ,Pos2 = cast('<x>' + replace(A.SomeCol,' ','</x><x>')+'</x>' as xml).value('/x[2]','varchar(50)')
 From  @YourTable A
SomeCol                 Pos2
The Boeing Corporation  Boeing