这种情况(关于字符串)的SQL语法如何写
表中某个字段值(箱号)如下:
箱号---------单箱毛重(Kg)-----
1-10 21
11-17 30
18-20 25
..... ...
现在有个箱号:12,如何找出这个(12)箱号属于哪一条记录中
想要得出的结果是11-17这一条记录
用SQL语法如何实现?
--------------------------------------
字符串
[解决办法]
create table #tb(箱号 varchar(10),毛重 int)
insert into #tb
select '1-10',21
union all select '11-17',30
union all select '18-20',25
declare @v varchar(10)
set @v='12'
select *
from #tb
where @v between left(箱号,charindex('-',箱号)-1)
and right(箱号,len(箱号)-charindex('-',箱号))
drop table #tb
--结果
/*
11-1730
*/