select * from tb where cast(substring(fp,3,len(fp)) as int)>=3
and cast(substring(fp,3,len(fp)) as int)<=7
order by cast(substring(fp,3,len(fp)) as int)
------解决方案--------------------
use Tempdb
go
--> -->
declare @FPnm table([FP] nvarchar(6))
Insert @FPnm
select N'AP001' union all
select N'AP002' union all
select N'AP003' union all
select N'AP004' union all
select N'AP005' union all
select N'AP006' union all
select N'AP007' union all
select N'AP008' union all
select N'AP0051' union all
select N'AP0052' union all
select N'AP0060'
Select * from @FPnm where cast(stuff([FP],1,2,'') as int) between 3 and 7
/*
FP
AP003
AP004
AP005
AP006
AP007
*/
------解决方案--------------------
select * from @FPnm where FP >='AP003' and FP <='AP007' and LEN(fp)=5 order by fp 最简单的方法是这样吧 ------解决方案--------------------
select * from FPnm where FP >='AP003' and FP <='AP007' and LEN(fp)<=5 order by fp
------解决方案--------------------
select fp from fpnm where cast(isnull(stuff(fp,1,2,''),0) as int) between 3 and 7 ------解决方案--------------------
select * from FPnm where convert(int,right(FP,3))>=3 and convert(int,right(FP,3))<=7