[英]Substring a word from string with charindex in SQL server
我正在尝试编写一个查询以从字符串中提取一个单词。 例如,我想从句子中得到Final
这个词: this is the final exam
。
我只想使用 charindex 获得“final”这个词来确定 substring function 的开始和结束。
我想这就是你所要求的。 请看一下:
Declare @start INT;
Declare @end int;
set @start=CHARINDEX('Fi','this is the final exam');
set @end =CHARINDEX('al','this is the final exam');
if(@start >0 and @end>0)
Begin
SELECT
SUBSTRING('this is the final exam',
@start,
5)
END
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.