name
qqq_bbb_cccc_eee
如何在SQL里把bbb取出来啊。
29 个解决方案
#1
substring(name,4,3)
#2
substring(name,5,3)
#3
SUBSTRING
语法
SUBSTRING ( expression , start , length )
语法
SUBSTRING ( expression , start , length )
#4
--如果位置固定
select substring(name,5,3) from tb
--如果位置不固定
select substring(name , charindex('-',name)+1 , charindex('-',name,charindex('-',name)+1) - charindex('-',name) -1) from tb
#5
declare @name as varchar(20)
set @name = 'qqq_bbb_cccc_eee'
select 位置固定 = substring(@name , 5 ,3)
select 位置不固定 = substring(@name , charindex('_',@name)+1 , charindex('_',@name,charindex('_',@name)+1) - charindex('_',@name) -1)
/*
位置固定
------
bbb
(所影响的行数为 1 行)
位置不固定
--------------------
bbb
(所影响的行数为 1 行)
*/
#6
create table #t(name varchar(50))
insert #t select 'qqq_bbb_cccc_eee'
-----------------------------------
select parsename(replace(name,'_','.'),3) from #t
insert #t select 'qqq_bbb_cccc_eee'
-----------------------------------
select parsename(replace(name,'_','.'),3) from #t
#7
name
qqq_bbb_cccc_eee
如何在SQL里把bbb取出来啊。
--------------------------
有问题呢?
到底你是什么意思,如果只是bbb取出来
那你直接SELECT 'bbb'不就得了,问题有歧义。
qqq_bbb_cccc_eee
如何在SQL里把bbb取出来啊。
--------------------------
有问题呢?
到底你是什么意思,如果只是bbb取出来
那你直接SELECT 'bbb'不就得了,问题有歧义。
#8
位置不固定
declare @str1 nvarchar(100),@str2 nvarchar(100)
set @str1 = 'ddddddqq_bbdddqq_cccc_eee'
set @str2=stuff(@str1,charindex('_',@str1,1),1,'m')
select substring(@str1,charindex('_',@str1,1)+1,charindex('_',@str2,1)-charindex('_',@str1,1)-1)
#9
我想说的是 ;
这个字段的值是有下划线分割的字符,位置也是不固定的。
name
qqq_bbdddaaab_cccc_eee
qqq_bbaaab_cccc
qqq_bdddbb
我现在需要在查询取出第二部分的字符即:
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',@name)+1) - charindex('_',name) -1)
但是这样,如果字段只有两部分如:qqq_bdddbb就会出错。
这个字段的值是有下划线分割的字符,位置也是不固定的。
name
qqq_bbdddaaab_cccc_eee
qqq_bbaaab_cccc
qqq_bdddbb
我现在需要在查询取出第二部分的字符即:
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',@name)+1) - charindex('_',name) -1)
但是这样,如果字段只有两部分如:qqq_bdddbb就会出错。
#10
select reverse(parsename(replace(reverse(name),'_','.'),2)) from #t
#11
侄name值莨
name
dfsdfds_dddfa_fsdfa_dsfasd
sdfsdaf_fdsfg_fds_fsdafs
dafasdf_fasdf_fdsfsd
sdfds_dsfasd
要诓询时训诙值值取前娌恐和烘部侄要
玫
dddfa
fdsfg
fasdf
dsfasd
楼 ;
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',name)+1) - charindex('_',name) -1)
from b
械sdfds_dsfasd时
Invalid length parameter passed to the substring function.
name
dfsdfds_dddfa_fsdfa_dsfasd
sdfsdaf_fdsfg_fds_fsdafs
dafasdf_fasdf_fdsfsd
sdfds_dsfasd
要诓询时训诙值值取前娌恐和烘部侄要
玫
dddfa
fdsfg
fasdf
dsfasd
楼 ;
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',name)+1) - charindex('_',name) -1)
from b
械sdfds_dsfasd时
Invalid length parameter passed to the substring function.
#12
字段name得值有以下数据构成
dfsdfds_dddfa_fsdfa_dsfasd
sdfsdaf_fdsfg_fds_fsdafs
dafasdf_fasdf_fdsfsd
sdfds_dsfasd
需要在查询数据时把第二部分得值取出来,
即
dddfa
fdsfg
fasdf
dsfasd
楼上:
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',name)+1) - charindex('_',name) -1)
from b
运行到sdfds_dsfasd时出错
Invalid length parameter passed to the substring function.
dfsdfds_dddfa_fsdfa_dsfasd
sdfsdaf_fdsfg_fds_fsdafs
dafasdf_fasdf_fdsfsd
sdfds_dsfasd
需要在查询数据时把第二部分得值取出来,
即
dddfa
fdsfg
fasdf
dsfasd
楼上:
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',name)+1) - charindex('_',name) -1)
from b
运行到sdfds_dsfasd时出错
Invalid length parameter passed to the substring function.
#13
to:10楼wgzaaa
得到的全是null值
得到的全是null值
#14
select name=
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
#15
select name=
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
#16
select name=
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
#17
顶 下,等高人 。
#18
create table b (name varchar(50))
insert b select 'dfsdfds_dddfa_fsdfa_dsfasd' union all select
'sdfsdaf_fdsfg_fds_fsdafs' union all select
'dafasdf_fasdf_fdsfsd' union all select
'sdfds_dsfasd'
select substring(name , charindex( '_',name+'_')+1 , charindex( '_',name+'_',charindex( '_',name+'_')+1) - charindex( '_',name+'_') -1) from b
insert b select 'dfsdfds_dddfa_fsdfa_dsfasd' union all select
'sdfsdaf_fdsfg_fds_fsdafs' union all select
'dafasdf_fasdf_fdsfsd' union all select
'sdfds_dsfasd'
select substring(name , charindex( '_',name+'_')+1 , charindex( '_',name+'_',charindex( '_',name+'_')+1) - charindex( '_',name+'_') -1) from b
#19
结果:dddfa
fdsfg
fasdf
dsfasd
fdsfg
fasdf
dsfasd
#20
如果字段只有两部分如:qqq_bdddbb就会出错。这是因为两部分的时候没有'_',你的加 charindex( '_ ',name+ '_ ',charindex( '_ ',name+ '_ ')+1)
#21
create function kkk(@text varchar(100))
returns varchar(50)
as
begin
declare @p varchar(50)
declare @num int
if(charindex('_',@text)>0)
begin
set @text=substring(@text,charindex('_',@text)+1,len(@text))
set @num=charindex('_',@text)
if(@num>0)set @p=substring(@text,1,charindex('_',@text)-1)
else set @p=@text
end
return @p
end
调用
select dbo.kkk('_bbb_asdf')
#22
declare @T table ([Name] varchar(300))
insert @T select 'dfsdfds_dddfa_fsdfa_dsfasd'
insert @T select 'sdfsdaf_fdsfg_fds_fsdafs'
insert @T select 'dafasdf_fasdf_fdsfsd'
insert @T select 'sdfds_dsfasd'
select case when len([Name])-len(REPLACE([Name],'_',''))>=2 then SUBSTRING([Name],charindex('_',[Name])+1,charindex('_',[Name],charindex('_',[Name])+1)-charindex('_',[Name])-1)
when len([Name])-len(REPLACE([Name],'_',''))=1 then SUBSTRING([Name],charindex('_',[Name])+1,len([Name])-charindex('_',[Name])) end
from @T
#23
--测试数据
declare @Test table(Col varchar(300))
insert @Test
select '1_1' union all
select '1.2_1.2_1.2' union all
select '1.2.3_1.2.3_1.2.3_1.2.3'
select Result=substring
(
Col+'_',
charindex('_',Col)+1,
charindex('_',Col+'_',charindex('_',Col)+1) - charindex('_',Col) - 1
)
from @Test
/*
Result
1
1.2
1.2.3
*/
--如果Col最多只有4部分(最多3个下划线):
select Result=replace(reverse(parsename(replace(reverse(replace(Col,'.','!@#$%^&*()')),'_','.'),2)),'!@#$%^&*()','.') from @Test
/*
Result
1
1.2
1.2.3
*/
#24
declare @num int
declare @str1 nvarchar(100),@str2 nvarchar(100)
set @str1 = '_bbdddqqeee_'
set @str2=stuff(@str1,charindex('_',@str1,1),1,'m')
if(charindex('_',@str2,1)>charindex('_',@str1,1))
set @num=charindex('_',@str2,1)-charindex('_',@str1,1)-1
else
set @num=len(@str1)-charindex('_',@str1,1)
select substring(@str1,charindex('_',@str1,1)+1,@num)
/*
----------------------------------------------------------------------------
bbdddqqeee
*/
#25
可以在字符的后面先加上个'_',这样应该就可以了
declare @name as varchar(20)
set @name = 'qqq_bbb_cccc_eee' + '_'
select 位置固定 = substring(@name , 5 ,3)
select 位置不固定 = substring(@name , charindex('_',@name)+1 , charindex('_',@name,charindex('_',@name)+1) - charindex('_',@name) -1)
declare @name as varchar(20)
set @name = 'qqq_bbb_cccc_eee' + '_'
select 位置固定 = substring(@name , 5 ,3)
select 位置不固定 = substring(@name , charindex('_',@name)+1 , charindex('_',@name,charindex('_',@name)+1) - charindex('_',@name) -1)
#26
declare @test table(id int ,sname varchar(50))
insert into @test
select 1,'qqq_bbb_cccc_eee'
select top 8000 id=identity(int,1,1)
into # from syscolumns
select
id=identity(int,1,1),a.id as AID,
sname=substring(a.sname,b.id,charindex('_',a.sname+'_',b.id)-b.id)
into #result
from @test a,# b
where
substring('_'+a.sname,b.id,1)='_' and a.id=1
select * from #result where aid=1 and id=2
drop table #,#result
#27
我的适合于 asd_bbdddqqeee_asd ,_bbdddqqeee_asd, _bbdddqqeee_, _bbdddqqeee
#28
....
#29
收藏了
#1
substring(name,4,3)
#2
substring(name,5,3)
#3
SUBSTRING
语法
SUBSTRING ( expression , start , length )
语法
SUBSTRING ( expression , start , length )
#4
--如果位置固定
select substring(name,5,3) from tb
--如果位置不固定
select substring(name , charindex('-',name)+1 , charindex('-',name,charindex('-',name)+1) - charindex('-',name) -1) from tb
#5
declare @name as varchar(20)
set @name = 'qqq_bbb_cccc_eee'
select 位置固定 = substring(@name , 5 ,3)
select 位置不固定 = substring(@name , charindex('_',@name)+1 , charindex('_',@name,charindex('_',@name)+1) - charindex('_',@name) -1)
/*
位置固定
------
bbb
(所影响的行数为 1 行)
位置不固定
--------------------
bbb
(所影响的行数为 1 行)
*/
#6
create table #t(name varchar(50))
insert #t select 'qqq_bbb_cccc_eee'
-----------------------------------
select parsename(replace(name,'_','.'),3) from #t
insert #t select 'qqq_bbb_cccc_eee'
-----------------------------------
select parsename(replace(name,'_','.'),3) from #t
#7
name
qqq_bbb_cccc_eee
如何在SQL里把bbb取出来啊。
--------------------------
有问题呢?
到底你是什么意思,如果只是bbb取出来
那你直接SELECT 'bbb'不就得了,问题有歧义。
qqq_bbb_cccc_eee
如何在SQL里把bbb取出来啊。
--------------------------
有问题呢?
到底你是什么意思,如果只是bbb取出来
那你直接SELECT 'bbb'不就得了,问题有歧义。
#8
位置不固定
declare @str1 nvarchar(100),@str2 nvarchar(100)
set @str1 = 'ddddddqq_bbdddqq_cccc_eee'
set @str2=stuff(@str1,charindex('_',@str1,1),1,'m')
select substring(@str1,charindex('_',@str1,1)+1,charindex('_',@str2,1)-charindex('_',@str1,1)-1)
#9
我想说的是 ;
这个字段的值是有下划线分割的字符,位置也是不固定的。
name
qqq_bbdddaaab_cccc_eee
qqq_bbaaab_cccc
qqq_bdddbb
我现在需要在查询取出第二部分的字符即:
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',@name)+1) - charindex('_',name) -1)
但是这样,如果字段只有两部分如:qqq_bdddbb就会出错。
这个字段的值是有下划线分割的字符,位置也是不固定的。
name
qqq_bbdddaaab_cccc_eee
qqq_bbaaab_cccc
qqq_bdddbb
我现在需要在查询取出第二部分的字符即:
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',@name)+1) - charindex('_',name) -1)
但是这样,如果字段只有两部分如:qqq_bdddbb就会出错。
#10
select reverse(parsename(replace(reverse(name),'_','.'),2)) from #t
#11
侄name值莨
name
dfsdfds_dddfa_fsdfa_dsfasd
sdfsdaf_fdsfg_fds_fsdafs
dafasdf_fasdf_fdsfsd
sdfds_dsfasd
要诓询时训诙值值取前娌恐和烘部侄要
玫
dddfa
fdsfg
fasdf
dsfasd
楼 ;
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',name)+1) - charindex('_',name) -1)
from b
械sdfds_dsfasd时
Invalid length parameter passed to the substring function.
name
dfsdfds_dddfa_fsdfa_dsfasd
sdfsdaf_fdsfg_fds_fsdafs
dafasdf_fasdf_fdsfsd
sdfds_dsfasd
要诓询时训诙值值取前娌恐和烘部侄要
玫
dddfa
fdsfg
fasdf
dsfasd
楼 ;
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',name)+1) - charindex('_',name) -1)
from b
械sdfds_dsfasd时
Invalid length parameter passed to the substring function.
#12
字段name得值有以下数据构成
dfsdfds_dddfa_fsdfa_dsfasd
sdfsdaf_fdsfg_fds_fsdafs
dafasdf_fasdf_fdsfsd
sdfds_dsfasd
需要在查询数据时把第二部分得值取出来,
即
dddfa
fdsfg
fasdf
dsfasd
楼上:
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',name)+1) - charindex('_',name) -1)
from b
运行到sdfds_dsfasd时出错
Invalid length parameter passed to the substring function.
dfsdfds_dddfa_fsdfa_dsfasd
sdfsdaf_fdsfg_fds_fsdafs
dafasdf_fasdf_fdsfsd
sdfds_dsfasd
需要在查询数据时把第二部分得值取出来,
即
dddfa
fdsfg
fasdf
dsfasd
楼上:
select substring(name , charindex('_',name)+1 , charindex('_',name,charindex('_',name)+1) - charindex('_',name) -1)
from b
运行到sdfds_dsfasd时出错
Invalid length parameter passed to the substring function.
#13
to:10楼wgzaaa
得到的全是null值
得到的全是null值
#14
select name=
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
#15
select name=
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
#16
select name=
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
(case when
charindex('_',right(name,len(name)-charindex('_',name)))>0
then
substring(name,charindex('_',name)+1,(charindex('_',name,charindex('_',name)+1)
-(charindex('_',name)+1)))
else
right(name,len(name)-charindex('_',name))
end
)
from
(
select 'aaa_kkk_as' as name
union all
select 'aaa_222'
) t
太复杂了 -. -
自己都不忍心看 等高人
#17
顶 下,等高人 。
#18
create table b (name varchar(50))
insert b select 'dfsdfds_dddfa_fsdfa_dsfasd' union all select
'sdfsdaf_fdsfg_fds_fsdafs' union all select
'dafasdf_fasdf_fdsfsd' union all select
'sdfds_dsfasd'
select substring(name , charindex( '_',name+'_')+1 , charindex( '_',name+'_',charindex( '_',name+'_')+1) - charindex( '_',name+'_') -1) from b
insert b select 'dfsdfds_dddfa_fsdfa_dsfasd' union all select
'sdfsdaf_fdsfg_fds_fsdafs' union all select
'dafasdf_fasdf_fdsfsd' union all select
'sdfds_dsfasd'
select substring(name , charindex( '_',name+'_')+1 , charindex( '_',name+'_',charindex( '_',name+'_')+1) - charindex( '_',name+'_') -1) from b
#19
结果:dddfa
fdsfg
fasdf
dsfasd
fdsfg
fasdf
dsfasd
#20
如果字段只有两部分如:qqq_bdddbb就会出错。这是因为两部分的时候没有'_',你的加 charindex( '_ ',name+ '_ ',charindex( '_ ',name+ '_ ')+1)
#21
create function kkk(@text varchar(100))
returns varchar(50)
as
begin
declare @p varchar(50)
declare @num int
if(charindex('_',@text)>0)
begin
set @text=substring(@text,charindex('_',@text)+1,len(@text))
set @num=charindex('_',@text)
if(@num>0)set @p=substring(@text,1,charindex('_',@text)-1)
else set @p=@text
end
return @p
end
调用
select dbo.kkk('_bbb_asdf')
#22
declare @T table ([Name] varchar(300))
insert @T select 'dfsdfds_dddfa_fsdfa_dsfasd'
insert @T select 'sdfsdaf_fdsfg_fds_fsdafs'
insert @T select 'dafasdf_fasdf_fdsfsd'
insert @T select 'sdfds_dsfasd'
select case when len([Name])-len(REPLACE([Name],'_',''))>=2 then SUBSTRING([Name],charindex('_',[Name])+1,charindex('_',[Name],charindex('_',[Name])+1)-charindex('_',[Name])-1)
when len([Name])-len(REPLACE([Name],'_',''))=1 then SUBSTRING([Name],charindex('_',[Name])+1,len([Name])-charindex('_',[Name])) end
from @T
#23
--测试数据
declare @Test table(Col varchar(300))
insert @Test
select '1_1' union all
select '1.2_1.2_1.2' union all
select '1.2.3_1.2.3_1.2.3_1.2.3'
select Result=substring
(
Col+'_',
charindex('_',Col)+1,
charindex('_',Col+'_',charindex('_',Col)+1) - charindex('_',Col) - 1
)
from @Test
/*
Result
1
1.2
1.2.3
*/
--如果Col最多只有4部分(最多3个下划线):
select Result=replace(reverse(parsename(replace(reverse(replace(Col,'.','!@#$%^&*()')),'_','.'),2)),'!@#$%^&*()','.') from @Test
/*
Result
1
1.2
1.2.3
*/
#24
declare @num int
declare @str1 nvarchar(100),@str2 nvarchar(100)
set @str1 = '_bbdddqqeee_'
set @str2=stuff(@str1,charindex('_',@str1,1),1,'m')
if(charindex('_',@str2,1)>charindex('_',@str1,1))
set @num=charindex('_',@str2,1)-charindex('_',@str1,1)-1
else
set @num=len(@str1)-charindex('_',@str1,1)
select substring(@str1,charindex('_',@str1,1)+1,@num)
/*
----------------------------------------------------------------------------
bbdddqqeee
*/
#25
可以在字符的后面先加上个'_',这样应该就可以了
declare @name as varchar(20)
set @name = 'qqq_bbb_cccc_eee' + '_'
select 位置固定 = substring(@name , 5 ,3)
select 位置不固定 = substring(@name , charindex('_',@name)+1 , charindex('_',@name,charindex('_',@name)+1) - charindex('_',@name) -1)
declare @name as varchar(20)
set @name = 'qqq_bbb_cccc_eee' + '_'
select 位置固定 = substring(@name , 5 ,3)
select 位置不固定 = substring(@name , charindex('_',@name)+1 , charindex('_',@name,charindex('_',@name)+1) - charindex('_',@name) -1)
#26
declare @test table(id int ,sname varchar(50))
insert into @test
select 1,'qqq_bbb_cccc_eee'
select top 8000 id=identity(int,1,1)
into # from syscolumns
select
id=identity(int,1,1),a.id as AID,
sname=substring(a.sname,b.id,charindex('_',a.sname+'_',b.id)-b.id)
into #result
from @test a,# b
where
substring('_'+a.sname,b.id,1)='_' and a.id=1
select * from #result where aid=1 and id=2
drop table #,#result
#27
我的适合于 asd_bbdddqqeee_asd ,_bbdddqqeee_asd, _bbdddqqeee_, _bbdddqqeee
#28
....
#29
收藏了