Declare @Str Varchar(100) Declare @Index Int Set @Str='910*122*16' Set @Index=CHARINDEX('*',@Str) Set @Str=SUBSTRING(@Str,@Index+1,LEN(@Str)-@Index) Set @Index=CharIndex('*',@Str) Set @Str=SUBSTRING(@Str,1,@Index-1) Select @Str
declare @str varchar(255),@context nvarchar(255) set @str='910*150*16' declare @Curr_Index int =0set @Curr_Index = CHARINDEX('*',@str) select @context = SUBSTRING(@str,@Curr_Index+1,LEN(@str))declare @Curr_Index_1 int =0 declare @Next_Index_1 int =0 set @Curr_Index_1 = CHARINDEX('*',@context) if(@Curr_Index_1 = 0) begin select @context end else begin select @context = SUBSTRING(@context,0,@Curr_Index_1) select @context end
parsename(replace(col,'*','.'),1)
select reverse(substring(reverse(col),1,charindex('*',reverse(col))-1)) from tb
set @str='910*122*16'
--set @str='1500*150*6'select reverse(substring(reverse(@str),1,charindex('*',reverse(@str))-1))
--------------------------------------------------
16(1 行受影响)
910*122*162345
1500*150*62313123
字符串长度不一定,但是两个*一定
如何截取出第二个*后面的数字
*/
select substring('910*122*162345',
charindex('*','910*122*162345',charindex('*','910*122*162345')+1)+1,
LEN('910*122*162345')-
charindex('*','910*122*162345',charindex('*','910*122*162345')+1)+1
)
select substring('910*122*16',charindex('*','910*122*16',charindex('*','910*122*16',1)+1)+1,len('910*122*16'))
Declare @Str Varchar(100)
Declare @Index Int
Set @Str='910*122*16'
Set @Index=CHARINDEX('*',@Str)
Set @Str=SUBSTRING(@Str,@Index+1,LEN(@Str)-@Index)
Set @Index=CharIndex('*',@Str)
Set @Str=SUBSTRING(@Str,1,@Index-1)
Select @Str
set @str='910*150*16'
declare @Curr_Index int =0set @Curr_Index = CHARINDEX('*',@str)
select @context = SUBSTRING(@str,@Curr_Index+1,LEN(@str))declare @Curr_Index_1 int =0
declare @Next_Index_1 int =0
set @Curr_Index_1 = CHARINDEX('*',@context)
if(@Curr_Index_1 = 0)
begin
select @context
end
else
begin
select @context = SUBSTRING(@context,0,@Curr_Index_1)
select @context
end