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