SQL语句 怎么获取第一个逗号到第二个逗号之间或者第二个逗号到第三个逗号之间的字符串
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/28 15:08:27
SQL语句 怎么获取第一个逗号到第二个逗号之间或者第二个逗号到第三个逗号之间的字符串
比如‘abcd,1234,ABCD,efg’获取 1234或者ABCD
还有‘abcd,1234,ABCD,5678’ 获得5678的
比如‘abcd,1234,ABCD,efg’获取 1234或者ABCD
还有‘abcd,1234,ABCD,5678’ 获得5678的
Create FUNCTION [dbo].UFN_SubIndex
(
@p_value nvarchar(100),
@p_split nvarchar(1)=',',
@p_index int
)
RETURNS nvarchar(50)
AS
Begin
DECLARE @CurrentIndex int;
DECLARE @Length int;
DECLARE @NextIndex int;
DECLARE @ReturnText nvarchar(50);
Set @CurrentIndex=1;
Set @NextIndex=@p_index
Set @Length=LEN(@p_value)
if @p_index<0
set @p_index=0;
WHILE(@CurrentIndex<=@Length and @p_index>=0)
BEGIN
set @NextIndex=charindex(@p_split,@p_value,@CurrentIndex);
set @p_index =@p_index-1;
IF(@NextIndex=0 OR @NextIndex IS NULL)
Begin
set @NextIndex=@Length+1;
set @ReturnText=substring(@p_value,@CurrentIndex,@NextIndex-@CurrentIndex);
set @CurrentIndex=@NextIndex+1;
End
Else
Begin
set @NextIndex=@NextIndex;
set @ReturnText=substring(@p_value,@CurrentIndex,@NextIndex-@CurrentIndex);
set @CurrentIndex=@NextIndex+1;
End
END
RETURN @ReturnText;
End
GO
select dbo.UFN_SubIndex('abcd,1234,ABCD,efg', ',', 2)
select dbo.UFN_SubIndex('abcd,1234,ABCD,5678', ',', 3)
(
@p_value nvarchar(100),
@p_split nvarchar(1)=',',
@p_index int
)
RETURNS nvarchar(50)
AS
Begin
DECLARE @CurrentIndex int;
DECLARE @Length int;
DECLARE @NextIndex int;
DECLARE @ReturnText nvarchar(50);
Set @CurrentIndex=1;
Set @NextIndex=@p_index
Set @Length=LEN(@p_value)
if @p_index<0
set @p_index=0;
WHILE(@CurrentIndex<=@Length and @p_index>=0)
BEGIN
set @NextIndex=charindex(@p_split,@p_value,@CurrentIndex);
set @p_index =@p_index-1;
IF(@NextIndex=0 OR @NextIndex IS NULL)
Begin
set @NextIndex=@Length+1;
set @ReturnText=substring(@p_value,@CurrentIndex,@NextIndex-@CurrentIndex);
set @CurrentIndex=@NextIndex+1;
End
Else
Begin
set @NextIndex=@NextIndex;
set @ReturnText=substring(@p_value,@CurrentIndex,@NextIndex-@CurrentIndex);
set @CurrentIndex=@NextIndex+1;
End
END
RETURN @ReturnText;
End
GO
select dbo.UFN_SubIndex('abcd,1234,ABCD,efg', ',', 2)
select dbo.UFN_SubIndex('abcd,1234,ABCD,5678', ',', 3)
SQL语句 怎么获取第一个逗号到第二个逗号之间或者第二个逗号到第三个逗号之间的字符串
请告诉指导正则表达式,获取第2个逗号与第3个逗号之间的内容
sed的第N个办角逗号到第M个半角逗号这样的要怎么写?
8个字的成语要有逗号!
不定式作目的状语可以放在逗号隔开的第二个句子的句首吗
这句英文如何理解,第二个逗号后面的请详细分析一下
(英语达人来)下句话中第二个逗号后的结构剖析一下!
用两个一切造句第一个一切前面有逗号
音标中各种符号的意思[,ɔpə'tju:niti]1.第一个左下角和第二个上面的像逗号的符号与像冒号
CO.,LTD为何有个逗号呀?
每一个关键词最多10个汉字关键词之间使用逗号分隔开!是甚么意思!
在C语言赋值语句中,给多个变量赋值,用逗号隔开,岂不是相当于一个逗号表达式?