34,590
社区成员
发帖
与我相关
我的任务
分享
create table T
(
T_Str varchar(8000)
)
insert T select '5,5'
insert T select '0,6'
insert T select '11,10'
insert T select '0,1'
insert T select '0,8'
insert T select '0,3'
insert T select '0,11'
insert T select '0,10'
insert T select '0,1'
insert T select '0,9'
select *
from T
where charindex(',',T_Str)>0
and cast(SUBSTRING(T_Str,charindex(',',T_Str)+1,len(T_Str)-charindex(',',T_Str)) as int) between 8 and 13
DECLARE @a table(floor varchar(20))
------------------------
INSERT @a SELECT '5,5'
UNION ALL SELECT '0,6'
UNION ALL SELECT '11,10'
UNION ALL SELECT '0,1'
UNION ALL SELECT '0,8'
UNION ALL SELECT '0,3'
UNION ALL SELECT '0,11'
UNION ALL SELECT '0,10'
UNION ALL SELECT '0,1'
UNION ALL SELECT '0,9'
SELECT * FROM @a WHERE right('0'+parsename(replace(floor,',','.'),1),2) BETWEEN '08' AND '13'
/*floor
--------------------
11,10
0,8
0,11
0,10
0,9
(所影响的行数为 5 行)*/
declare @tab table(
[floor] varchar(10)
)
insert @tab select
'5,5'
union all select
'0,6'
union all select
'11,10'
union all select
'0,1'
union all select
'0,8'
union all select
'0,3'
union all select
'0,11'
union all select
'0,10'
union all select
'0,1'
union all select
'0,9'
select * from @tab
where PARSENAME(REPLACE ([floor],',','.'),1) between 8 and 13
--结果
floor
----------
11,10
0,8
0,11
0,10
0,9
(5 行受影响)
create table #t (num varchar(10))
insert into #t
select '5,5'
union all
select '0,6'
union all
select '11,10'
union all
select '0,1'
union all
select '0,8'
union all
select '0,3'
union all
select '0,11'
union all
select '0,10'
union all
select '0,1'
union all
select '0,9'
select * from #t
where convert(tinyint,substring(num,charindex(',',num)+1,2)) between 8 and 13
drop table #t
declare @tab table(
[floor] varchar(10)
)
insert @tab select
'5,5'
union all select
'0,6'
union all select
'11,10'
union all select
'0,1'
union all select
'0,8'
union all select
'0,3'
union all select
'0,11'
union all select
'0,10'
union all select
'0,1'
union all select
'0,9'
select * from @tab
where cast(stuff([floor],1,charindex(',',[floor]),'') as int) between 8 and 13
--结果
floor
----------
11,10
0,8
0,11
0,10
0,9
(5 行受影响)
select * from tab
where cast(stuff(floor,1,charindex(',',floor),'') as int) between 8 and 13